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

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

Comments

Projects
None yet
2 participants

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.

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 added this to the Next Major Release milestone Dec 31, 2015

@jreback jreback modified the milestone: 0.18.0, Next Major Release Feb 19, 2016

@gfyoung gfyoung added a commit to gfyoung/pandas that referenced this issue Feb 19, 2016

@gfyoung gfyoung BUG: Return UTC DateTimeIndex when specified in to_datetime
Closes gh-11934.
fa794a5

jreback closed this in e39f63a Feb 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment