Raise error when trying to construct time-zone aware timestamps - #13830
Merged
Conversation
shwina
reviewed
Aug 7, 2023
Co-authored-by: Ashwin Srinath <3190405+shwina@users.noreply.github.com>
galipremsagar
commented
Aug 7, 2023
galipremsagar
commented
Aug 7, 2023
bdice
reviewed
Aug 7, 2023
| other = other.to_datetime64() | ||
| elif isinstance(other, pd.Timedelta): | ||
| other = other.to_timedelta64() | ||
| elif isinstance(other, datetime.datetime): |
Contributor
There was a problem hiding this comment.
What about TZ-aware datetime.datetime objects? e.g.
>>> import datetime
>>> datetime.datetime.now(datetime.timezone.utc)
datetime.datetime(2023, 8, 7, 20, 47, 48, 483493, tzinfo=datetime.timezone.utc)Do those need to error, too? On conversion to np.datetime64, I get a warning. Is that sufficient?
>>> np.datetime64(datetime.datetime(2023, 8, 7, 20, 47, 48, 483493, tzinfo=datetime.timezone.utc))
<stdin>:1: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
numpy.datetime64('2023-08-07T20:47:48.483493')
Contributor
Author
There was a problem hiding this comment.
I think we should raise for it too. Good catch, I thought datetime was tz agnostic.
Contributor
Author
There was a problem hiding this comment.
@bdice I updated the code to handle datetime.datetime objects aswell.
bdice
approved these changes
Aug 7, 2023
Contributor
Author
|
/merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes: #13825 This PR raises an error when a time-zone-aware scalar is passed to binops or cudf scalar construction.
Checklist