-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: expand acceptable types for pd.to_datetime() #46273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
9e57d6d
2abbc57
99158b1
0f4130d
24ecfe2
64f00d5
1ee6e00
5761bf2
84b119f
5232375
64feddd
1cc352a
06a4028
957372c
8801db6
ff7586f
54d937f
dcbde37
b451ca8
f119579
52836e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from typing import ( | ||
TYPE_CHECKING, | ||
Callable, | ||
Dict, | ||
Hashable, | ||
List, | ||
Tuple, | ||
|
@@ -79,7 +80,10 @@ | |
if TYPE_CHECKING: | ||
from pandas._libs.tslibs.nattype import NaTType | ||
|
||
from pandas import Series | ||
from pandas import ( | ||
DataFrame, | ||
Series, | ||
) | ||
|
||
# --------------------------------------------------------------------- | ||
# types used in annotations | ||
|
@@ -89,6 +93,7 @@ | |
DatetimeScalar = Union[Scalar, datetime] | ||
|
||
DatetimeScalarOrArrayConvertible = Union[DatetimeScalar, ArrayConvertible] | ||
DictConvertible = Union[Dict[str, List], "DataFrame"] | ||
Dr-Irv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
start_caching_at = 50 | ||
|
||
|
||
|
@@ -640,13 +645,13 @@ def to_datetime( | |
infer_datetime_format: bool = ..., | ||
origin=..., | ||
cache: bool = ..., | ||
) -> Timestamp | NaTType: | ||
) -> Timestamp: | ||
... | ||
|
||
|
||
@overload | ||
def to_datetime( | ||
arg: Series, | ||
arg: Series | DictConvertible, | ||
errors: str = ..., | ||
dayfirst: bool = ..., | ||
yearfirst: bool = ..., | ||
|
@@ -663,7 +668,7 @@ def to_datetime( | |
|
||
@overload | ||
def to_datetime( | ||
arg: list | tuple | np.ndarray, | ||
arg: list | tuple | np.ndarray | Index | ExtensionArray, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sequence? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, can't use Keeping unchanged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could replace about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
errors: str = ..., | ||
dayfirst: bool = ..., | ||
yearfirst: bool = ..., | ||
|
@@ -679,7 +684,7 @@ def to_datetime( | |
|
||
|
||
def to_datetime( | ||
arg: DatetimeScalarOrArrayConvertible, | ||
arg: DatetimeScalarOrArrayConvertible | DictConvertible, | ||
errors: str = "raise", | ||
dayfirst: bool = False, | ||
yearfirst: bool = False, | ||
|
@@ -1067,10 +1072,10 @@ def to_datetime( | |
# "Union[float, str, datetime, List[Any], Tuple[Any, ...], ExtensionArray, | ||
# ndarray[Any, Any], Series]"; expected "Union[List[Any], Tuple[Any, ...], | ||
# Union[Union[ExtensionArray, ndarray[Any, Any]], Index, Series], Series]" | ||
arg = cast( | ||
argc = cast( | ||
Union[list, tuple, ExtensionArray, np.ndarray, "Series", Index], arg | ||
) | ||
cache_array = _maybe_cache(arg, format, cache, convert_listlike) | ||
cache_array = _maybe_cache(argc, format, cache, convert_listlike) | ||
except OutOfBoundsDatetime: | ||
# caching attempts to create a DatetimeIndex, which may raise | ||
# an OOB. If that's the desired behavior, then just reraise... | ||
|
@@ -1081,9 +1086,9 @@ def to_datetime( | |
|
||
cache_array = Series([], dtype=object) # just an empty array | ||
if not cache_array.empty: | ||
result = _convert_and_box_cache(arg, cache_array) | ||
result = _convert_and_box_cache(argc, cache_array) | ||
else: | ||
result = convert_listlike(arg, format) | ||
result = convert_listlike(argc, format) | ||
else: | ||
result = convert_listlike(np.array([arg]), format)[0] | ||
if isinstance(arg, bool) and isinstance(result, np.bool_): | ||
|
Uh oh!
There was an error while loading. Please reload this page.