Skip to content

Commit 539c842

Browse files
committed
TYP: Improve to_datetime
1 parent d360eb6 commit 539c842

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pandas-stubs/core/tools/datetimes.pyi

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from datetime import datetime
22
from typing import (
33
Literal,
4+
Sequence,
45
TypedDict,
56
Union,
67
overload,
78
)
89

910
import numpy as np
11+
import pandas as pd
1012
from pandas import (
1113
Index,
1214
Timestamp,
@@ -25,6 +27,7 @@ from pandas._typing import (
2527
AnyArrayLike,
2628
DateTimeErrorChoices,
2729
IgnoreRaise,
30+
npt,
2831
)
2932

3033
ArrayConvertible: TypeAlias = Union[list, tuple, AnyArrayLike]
@@ -53,9 +56,6 @@ class FulldatetimeDict(YearMonthDayDict, total=False):
5356

5457
DictConvertible: TypeAlias = Union[FulldatetimeDict, DataFrame]
5558

56-
def should_cache(
57-
arg: ArrayConvertible, unique_share: float = ..., check_count: int | None = ...
58-
) -> bool: ...
5959
@overload
6060
def to_datetime(
6161
arg: DatetimeScalar,
@@ -67,7 +67,7 @@ def to_datetime(
6767
exact: bool = ...,
6868
unit: str | None = ...,
6969
infer_datetime_format: bool = ...,
70-
origin=...,
70+
origin: int | Literal["julian", "unix"] | pd.Timestamp = ...,
7171
cache: bool = ...,
7272
) -> Timestamp: ...
7373
@overload
@@ -81,11 +81,12 @@ def to_datetime(
8181
exact: bool = ...,
8282
unit: str | None = ...,
8383
infer_datetime_format: bool = ...,
84-
origin=...,
84+
origin: Literal["julian", "unix"] | pd.Timestamp = ...,
8585
cache: bool = ...,
8686
) -> Timestamp | NaTType: ...
8787
@overload
8888
def to_datetime(
89+
# TODO: Test dataframe return type
8990
arg: Series | DictConvertible,
9091
errors: DateTimeErrorChoices = ...,
9192
dayfirst: bool = ...,
@@ -95,12 +96,23 @@ def to_datetime(
9596
exact: bool = ...,
9697
unit: str | None = ...,
9798
infer_datetime_format: bool = ...,
98-
origin=...,
99+
origin: int | Literal["julian", "unix"] | pd.Timestamp = ...,
99100
cache: bool = ...,
100101
) -> TimestampSeries: ...
101102
@overload
102103
def to_datetime(
103-
arg: list | tuple | np.ndarray | Index | ExtensionArray,
104+
# TODO: Test other types
105+
arg: list[str]
106+
| list[int]
107+
| list[float]
108+
| list[datetime]
109+
| tuple[int | float | str | datetime, ...]
110+
| npt.NDArray[np.datetime64]
111+
| npt.NDArray[np.str_]
112+
| npt.NDArray[np.int_]
113+
| npt.NDArray[np.float_]
114+
| Index
115+
| ExtensionArray,
104116
errors: DateTimeErrorChoices = ...,
105117
dayfirst: bool = ...,
106118
yearfirst: bool = ...,
@@ -109,7 +121,6 @@ def to_datetime(
109121
exact: bool = ...,
110122
unit: str | None = ...,
111123
infer_datetime_format: bool = ...,
112-
origin=...,
124+
origin: int | Literal["julian", "unix"] | pd.Timestamp = ...,
113125
cache: bool = ...,
114126
) -> DatetimeIndex: ...
115-
def to_time(arg, format=..., infer_time_format: bool = ..., errors: str = ...): ...

0 commit comments

Comments
 (0)