BUG: fix to_datetime(dti, utc=True) by jbrockmendel · Pull Request #27733 · pandas-dev/pandas (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation14 Commits5 Checks0 Files changed
Conversation
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
[ Show hidden characters]({{ revealButtonHref }})
- closes #xxxx
- tests added / passed
- passes
black pandas - passes
git diff upstream/master -u -- "*.py" | flake8 --diff - whatsnew entry
ATM to_datetime(naive_dti, utc=True) returns naive incorrect, same for naive DatetimeArray
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
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.
| 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`) |
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: |
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:
...
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?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request
WillAyd pushed a commit that referenced this pull request
quintusdias pushed a commit to quintusdias/pandas_dev that referenced this pull request
BUG: fix to_datetime(dti, utc=True)
whatsnew, suggested edits
parametrize
backquotes