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

API/DOC: to_series keep_tz behaviour for UTC timezone #9562

Closed
jorisvandenbossche opened this issue Feb 27, 2015 · 6 comments
Closed

API/DOC: to_series keep_tz behaviour for UTC timezone #9562

jorisvandenbossche opened this issue Feb 27, 2015 · 6 comments

Comments

@jorisvandenbossche
Copy link
Member

The docstring of to_series says for keep_tz=True: "If the timezone is not set or is UTC, the resulting Series will have a datetime64[ns] dtype. Otherwise the Series will have an object dtype."

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.to_series.html

But is seems that also for UTC, keep_tz=True does the conversion to object/Timestamp?

In [1]: idx = pd.date_range('1/1/2000', periods=20, freq='1H', tz='UTC')

In [2]: idx
Out[2]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01 00:00:00+00:00, ..., 2000-01-01 19:00:00+00:00]
Length: 20, Freq: H, Timezone: UTC

In [3]: idx.to_series()[0]
Out[3]: Timestamp('2000-01-01 00:00:00')

In [4]: idx.to_series(keep_tz=True)[0]
Out[4]: Timestamp('2000-01-01 00:00:00+0000', tz='UTC', offset='H')
@jorisvandenbossche
Copy link
Member Author

@jreback you put this in I think. Should be change the docs, or change the implementation?

I would find it more logical to not make this exception for UTC (so keep the behaviour and change the docs)

@jorisvandenbossche jorisvandenbossche added this to the 0.16.0 milestone Feb 27, 2015
@jorisvandenbossche
Copy link
Member Author

Ah, but, this behaviour seems to have changed from 0.14 to 0.15. Originally in 0.14, the behaviour was as described in the docs

@jreback
Copy link
Contributor

jreback commented Feb 27, 2015

this was a bug in that we do want to actually preserve the UTC tz on the resulting Series (IOW it becomes object dtype). So I think the doc-string is wrong. The behavior is correct, otherwise a UTC tz is effectively lost (by being converted to naive)

@jreback jreback added the Docs label Feb 27, 2015
@jreback
Copy link
Contributor

jreback commented Feb 27, 2015

closed by 8ef921f

@jreback jreback closed this as completed Feb 27, 2015
@jreback
Copy link
Contributor

jreback commented Feb 27, 2015

FYI, I think that we could basically drop this paramater (which is an API change because the default would change), and automatically preserve the character of the index when converting to a series, once DatetimeTZBlock blocks become a reality. (I added this originally because the perf impact is pretty big once you convert to object dtypes)

@jorisvandenbossche
Copy link
Member Author

Yes, once a timezone aware DatetimeBlock is in place, we can certainly consider that.

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

No branches or pull requests

2 participants