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

DataFrame.reset_index() loses timezone #2262

Closed
jim22k opened this issue Nov 15, 2012 · 0 comments
Closed

DataFrame.reset_index() loses timezone #2262

jim22k opened this issue Nov 15, 2012 · 0 comments
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@jim22k
Copy link

jim22k commented Nov 15, 2012

When timezone-aware datetime.datetime objects are used as the index of a DataFrame via set_index(), undoing the operation with reset_index() loses the timezone.

After the round-trip, the datetime.datetime column becomes a datetime64[ns] column, which can be considered a feature, not a bug. The times are correctly converted to UTC (which is good if you're going to lose the timezone), but the loss of timezone information seems like a bug.

This has been tested against version 0.9.1 on Python 2.7 (Windows 32-bit)

Code to recreate

import datetime, dateutil, pandas as pd
tzoffset = dateutil.tz.tzoffset(None, -5*60*60)
ts = datetime.datetime(2012,11,15,10,38,4,tzinfo=tzoffset)
print ts # this has a timezone
df = pd.DataFrame([[ts, 15]], columns=['ts', 'val'])
dfi = df.set_index('ts')
print dfi.index # this has a timezone
df2 = dfi.reset_index() # <-- This is where the timezone gets lost
print df2['ts'][0] # this doesn't have a timezone
print df2['ts'][0].to_datetime() # neither does this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

No branches or pull requests

2 participants