-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
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 |
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
@@ -31,7 +31,7 @@ Categorical | |||
|
|||
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
@@ -334,6 +334,9 @@ def _convert_listlike_datetimes( | |||
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.
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 pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
ATM
to_datetime(naive_dti, utc=True)
returns naive incorrect, same for naiveDatetimeArray