-
-
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
Conversation
This reverts commit 84b119f.
pandas/core/tools/datetimes.py
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
No, can't use Sequence
, because a string is a sequence, and that has to match the scalar type above this.
Keeping unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could replace np.ndarray | ExtensionArray
with ArrayLike
.
about Sequence
and str
: Does to_datetime require certain list/tuple elements? I'm sure that str
isn't part of Sequence[datetime.time]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_datetime
can take mixed lists/tuples of different kinds of scalars (datetimes, ints, floats, strings at a minimum), and I'm a bit hesitant to figure them all out to avoid making this too narrow. So I'm leaving this as list | tuple
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comments, otherwise looks good to me (still not a great fan of removing NaTType
but it makes it consistent with Timestamp/Timedelta).
thanks @Dr-Irv |
We document that
pd.to_datetime()
can accept aDataFrame
or "dict-like" as an argument, but the overloads did not specify that. This PR adds that.In addition, there was no overload for
Index
orExtensionArray
as an input type that converts toDatetimeIndex
Also, changed the overload for
pd.to_datetime()
on a scalar to only returnTimestamp
to make user code easier to write. E.g.,with the current version where
pd.to_datetime()
can returnTimestamp | NaTType
, users would have to do acast