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

DatetimeIndex.to_frame() inconsistent with dti.to_series().to_frame() #23728

Closed
jbrockmendel opened this issue Nov 15, 2018 · 7 comments
Closed
Labels
API Design Timezones Timezone data dtype

Comments

@jbrockmendel
Copy link
Member

For TZ-aware DatetimeIndex, to_series() drops the timezone unless we pass keep_tz=True

>>> dti = pd.date_range('1977-04-15', periods=3, freq='MS', tz='US/Hawaii')

>>> dti.to_series().to_frame().dtypes
0    datetime64[ns]

>>> dti.to_frame().dtypes
0    datetime64[ns, US/Hawaii]

IIRC there has been discussion about deprecating the need for keep_tz; this should be another reason to do so.

@jbrockmendel
Copy link
Member Author

Never mind, this was true in 0.23 but not in master.

@jbrockmendel
Copy link
Member Author

Actually, it looks like the keep_tz kwarg is not allowed for to_frame, so there is an inconsistency, just not the one I first thought.

@jbrockmendel jbrockmendel reopened this Nov 15, 2018
@mroeschke
Copy link
Member

Would the idea then be for to_series to always preserve the timezone?

@jbrockmendel
Copy link
Member Author

I think that's the most reasonable behavior yes. IIRC there was a historical reason why it wasnt the default. @jorisvandenbossche I think you've opened an issue about changing this behavior?

@mroeschke
Copy link
Member

xref #17832

@mroeschke mroeschke added API Design Timezones Timezone data dtype labels Nov 16, 2018
@jorisvandenbossche
Copy link
Member

Yes, we should deprecate keep_tz in to_series, that should make to_series and to_frame consistent.
Since that is covered in #17832, I think this can be closed?

@jorisvandenbossche
Copy link
Member

Opened a PR for it: #23739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

3 participants