Skip to content

Bug: UTC in to_datetime() not working in 0.17.1 #11934

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

Closed
yueatwork opened this issue Dec 30, 2015 · 1 comment
Closed

Bug: UTC in to_datetime() not working in 0.17.1 #11934

yueatwork opened this issue Dec 30, 2015 · 1 comment
Labels
Bug Timezones Timezone data dtype
Milestone

Comments

@yueatwork
Copy link

In the case below, setting utc=True in pandas.to_datetime actually removes the UTC attribute from the input:

import pandas as pd
import pytz
start = pd.Timestamp('2014-01-01', tz=pytz.UTC)
end = pd.Timestamp('2014-01-03', tz=pytz.UTC)
date_range = pd.bdate_range(start, end)
df = pd.DataFrame({'x':1}, index=date_range)
df.index
# DatetimeIndex([...], dtype='datetime64[ns, UTC]', freq='B')
pd.to_datetime(df.index, utc=True)
# DatetimeIndex([...], dtype='datetime64[ns]', freq='B')

the last function removes the UTC attribute from the input, even though utc is set to True.

This only happens in pandas 0.17.1. pandas 0.16.x have a different implementation and does not have this issue.

@jreback
Copy link
Contributor

jreback commented Dec 31, 2015

This line should be: https://github.com/pydata/pandas/blob/master/pandas/tseries/tools.py#L308

arg = arg.tz_convert(None).tz_localize('UTC')

though to be honest this flag is just confusing IMHO. Users should simply use tz_convert/tz_localize after pd.to_datetime if desired. This feels too automagicy to me.

@jreback jreback added this to the Next Major Release milestone Dec 31, 2015
@jreback jreback modified the milestones: 0.18.0, Next Major Release Feb 19, 2016
gfyoung added a commit to forking-repos/pandas that referenced this issue Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

2 participants