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

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 }})

jbrockmendel

ATM to_datetime(naive_dti, utc=True) returns naive incorrect, same for naive DatetimeArray

@jbrockmendel

mroeschke

mroeschke

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

jorisvandenbossche

@jbrockmendel

@jbrockmendel

updated with whatsnew and suggested edits

jreback

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.

@@ -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`)

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

mroeschke

@@ -334,6 +334,9 @@ def _convert_listlike_datetimes(
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.

jreback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mroeschke

@mroeschke

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request

Aug 5, 2019

@jbrockmendel

WillAyd pushed a commit that referenced this pull request

Aug 6, 2019

@meeseeksmachine @WillAyd

quintusdias pushed a commit to quintusdias/pandas_dev that referenced this pull request

Aug 16, 2019

@jbrockmendel @quintusdias