Skip to content
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

BUG: fix to_datetime(dti, utc=True) #27733

Merged
merged 5 commits into from Aug 5, 2019

Conversation

@jbrockmendel
Copy link
Member

commented Aug 3, 2019

  • 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

@mroeschke
Copy link
Member

left a comment

Probably needs a whatsnew entry

@jbrockmendel

This comment has been minimized.

Copy link
Member Author

commented Aug 4, 2019

updated with whatsnew and suggested edits

@jreback
Copy link
Contributor

left a comment

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

This comment has been minimized.

Copy link
@jreback

jreback Aug 4, 2019

Contributor

can you put utc=True in double-back quotes

@jreback jreback added this to the 0.25.1 milestone Aug 4, 2019

@@ -334,6 +334,9 @@ def _convert_listlike_datetimes(
return DatetimeIndex(arg, tz=tz, name=name)
except ValueError:
pass
elif tz:

This comment has been minimized.

Copy link
@mroeschke

mroeschke Aug 4, 2019

Member

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:
        ...

This comment has been minimized.

Copy link
@jbrockmendel

jbrockmendel Aug 5, 2019

Author Member
>>> 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?

This comment has been minimized.

Copy link
@mroeschke

mroeschke Aug 5, 2019

Member

Oh! It does work. box=True is the default so this looks correct.

@jreback
jreback approved these changes Aug 5, 2019
Copy link
Contributor

left a comment

lgtm, over to @mroeschke

@mroeschke mroeschke merged commit 61819ab into pandas-dev:master Aug 5, 2019

15 checks passed

codecov/patch 100% of diff hit (target 50%)
Details
codecov/project 93% (target 82%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
pandas-dev.pandas Build #20190804.31 succeeded
Details
pandas-dev.pandas (Checks) Checks succeeded
Details
pandas-dev.pandas (Docs) Docs succeeded
Details
pandas-dev.pandas (Linux py35_compat) Linux py35_compat succeeded
Details
pandas-dev.pandas (Linux py36_32bit) Linux py36_32bit succeeded
Details
pandas-dev.pandas (Linux py36_locale_slow) Linux py36_locale_slow succeeded
Details
pandas-dev.pandas (Linux py36_locale_slow_old_np) Linux py36_locale_slow_old_np succeeded
Details
pandas-dev.pandas (Linux py37_locale) Linux py37_locale succeeded
Details
pandas-dev.pandas (Linux py37_np_dev) Linux py37_np_dev succeeded
Details
pandas-dev.pandas (Windows py36_np15) Windows py36_np15 succeeded
Details
pandas-dev.pandas (Windows py37_np141) Windows py37_np141 succeeded
Details
pandas-dev.pandas (macOS py35_macos) macOS py35_macos succeeded
Details
@mroeschke

This comment has been minimized.

Copy link
Member

commented Aug 5, 2019

Thanks @jbrockmendel

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Aug 5, 2019

@jbrockmendel jbrockmendel deleted the jbrockmendel:todt branch Aug 5, 2019

WillAyd added a commit that referenced this pull request Aug 6, 2019
quintusdias added a commit to quintusdias/pandas_dev that referenced this pull request Aug 16, 2019
BUG: fix to_datetime(dti, utc=True) (pandas-dev#27733)
* BUG: fix to_datetime(dti, utc=True)

* whatsnew, suggested edits

* parametrize

* backquotes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.