Skip to content

Commit 87a0692

Browse files
committed
TYP: Improve to_datetime
1 parent d360eb6 commit 87a0692

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

pandas-stubs/core/tools/datetimes.pyi

Lines changed: 19 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: Literal["julian", "unix"] | pd.Timestamp = ...,
7171
cache: bool = ...,
7272
) -> Timestamp: ...
7373
@overload
@@ -81,7 +81,7 @@ 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
@@ -95,12 +95,23 @@ def to_datetime(
9595
exact: bool = ...,
9696
unit: str | None = ...,
9797
infer_datetime_format: bool = ...,
98-
origin=...,
98+
origin: Literal["julian", "unix"] | pd.Timestamp = ...,
9999
cache: bool = ...,
100100
) -> TimestampSeries: ...
101101
@overload
102102
def to_datetime(
103-
arg: list | tuple | np.ndarray | Index | ExtensionArray,
103+
# TODO: Test other types
104+
# TODO: Test dataframe return type
105+
arg: Sequence[int | float | datetime]
106+
| list[int | float | str | datetime]
107+
| tuple[int | float | str | datetime, ...]
108+
| npt.NDArray[np.datetime64]
109+
| npt.NDArray[np.str_]
110+
| npt.NDArray[np.int_]
111+
| npt.NDArray[np.float_]
112+
| Index
113+
| ExtensionArray
114+
| pd.DataFrame,
104115
errors: DateTimeErrorChoices = ...,
105116
dayfirst: bool = ...,
106117
yearfirst: bool = ...,
@@ -109,7 +120,6 @@ def to_datetime(
109120
exact: bool = ...,
110121
unit: str | None = ...,
111122
infer_datetime_format: bool = ...,
112-
origin=...,
123+
origin: Literal["julian", "unix"] | pd.Timestamp = ...,
113124
cache: bool = ...,
114125
) -> DatetimeIndex: ...
115-
def to_time(arg, format=..., infer_time_format: bool = ..., errors: str = ...): ...

0 commit comments

Comments
 (0)