-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: fix to_datetime(dti, utc=True) #27733
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
mroeschke
left a comment
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.
Probably needs a whatsnew entry
|
updated with whatsnew and suggested edits |
jreback
left a comment
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.
lgtm. small comments, ping on green.
doc/source/whatsnew/v0.25.1.rst
Outdated
| Datetimelike | ||
| ^^^^^^^^^^^^ | ||
|
|
||
| - Bug in :func:`to_datetime` where passing a timezone-naive :class:`DatetimeArray` or :class:`DatetimeIndex` and utc=True would incorrectly return a timezone-naive result (:issue:`27733`) |
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.
can you put utc=True in double-back quotes
| return DatetimeIndex(arg, tz=tz, name=name) | ||
| except ValueError: | ||
| pass | ||
| elif tz: |
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.
I think this would fail if a user passes to_datetime(np.array([...], dtype='datetime64[ns]'), utc=True)?
I was thinking more:
if box:
if not isinstance(arg, (DatetimeArray, ...)):
....
elif tz:
...
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.
>>> arr = np.arange(2).astype('datetime64[ns]')
>>> to_datetime(arr, utc=True)
DatetimeIndex(['1970-01-01 00:00:00+00:00', '1970-01-01 00:00:00.000000001+00:00'], dtype='datetime64[ns, UTC]', freq=None)
or are you suggesting that this is wrong because box=True was not passed?
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.
Oh! It does work. box=True is the default so this looks correct.
jreback
left a comment
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.
lgtm, over to @mroeschke
|
Thanks @jbrockmendel |
* BUG: fix to_datetime(dti, utc=True) * whatsnew, suggested edits * parametrize * backquotes
black pandasgit diff upstream/master -u -- "*.py" | flake8 --diffATM
to_datetime(naive_dti, utc=True)returns naive incorrect, same for naiveDatetimeArray