Remove keep_tz kwarg from DatetimeIndex.to_frame by jorisvandenbossche · Pull Request #17826 · pandas-dev/pandas (original) (raw)

To illustrate my 'suboptimal behaviour' of above (this is current master):

In [1]: dtidx = pd.date_range("2017-01-01", periods=3, tz='Europe/Brussels')

In [2]: dtidx
Out[2]: 
DatetimeIndex(['2017-01-01 00:00:00+01:00', '2017-01-02 00:00:00+01:00',
               '2017-01-03 00:00:00+01:00'],
              dtype='datetime64[ns, Europe/Brussels]', freq='D')

In [3]: dtidx.to_frame()
Out[3]: 
                                            0
2017-01-01 00:00:00+01:00 2016-12-31 23:00:00
2017-01-02 00:00:00+01:00 2017-01-01 23:00:00
2017-01-03 00:00:00+01:00 2017-01-02 23:00:00

In [5]: dtidx.to_frame().dtypes
Out[5]: 
0    datetime64[ns]
dtype: object

so it was a timezone aware index, but it lost its timezone information in conversion to a dataframe.