tz_localize() and tz_convert() doesn't work on MultiIndex · Issue #7846 · pandas-dev/pandas (original) (raw)
In [1]: import pandas as pd
In [2]: pd.__version__
Out[2]: '0.14.1'
In [3]: cohort_date = pd.date_range('20140701', periods=5, freq='D')
In [4]: event_date = pd.date_range('20140701', periods=5, freq='D')
In [5]: multi_index = pd.MultiIndex.from_product([cohort_date, event_date], names=['cohort_date', 'event_date'])
In [6]: df = pd.DataFrame(index=multi_index)
In [7]: df
Out[7]:
Empty DataFrame
Columns: []
Index: [(2014-07-01 00:00:00, 2014-07-01 00:00:00), (2014-07-01 00:00:00, 2014-07-02 00:00:00), (2014-07-01 00:00:00, 2014-07-03 00:00:00), (2014-07-01 00:00:00, 2014-07-04 00:00:00), (2014-07-01 00:00:00, 2014-07-05 00:00:00), (2014-07-02 00:00:00, 2014-07-01 00:00:00), (2014-07-02 00:00:00, 2014-07-02 00:00:00), (2014-07-02 00:00:00, 2014-07-03 00:00:00), (2014-07-02 00:00:00, 2014-07-04 00:00:00), (2014-07-02 00:00:00, 2014-07-05 00:00:00), (2014-07-03 00:00:00, 2014-07-01 00:00:00), (2014-07-03 00:00:00, 2014-07-02 00:00:00), (2014-07-03 00:00:00, 2014-07-03 00:00:00), (2014-07-03 00:00:00, 2014-07-04 00:00:00), (2014-07-03 00:00:00, 2014-07-05 00:00:00), (2014-07-04 00:00:00, 2014-07-01 00:00:00), (2014-07-04 00:00:00, 2014-07-02 00:00:00), (2014-07-04 00:00:00, 2014-07-03 00:00:00), (2014-07-04 00:00:00, 2014-07-04 00:00:00), (2014-07-04 00:00:00, 2014-07-05 00:00:00), (2014-07-05 00:00:00, 2014-07-01 00:00:00), (2014-07-05 00:00:00, 2014-07-02 00:00:00), (2014-07-05 00:00:00, 2014-07-03 00:00:00), (2014-07-05 00:00:00, 2014-07-04 00:00:00), (2014-07-05 00:00:00, 2014-07-05 00:00:00)]
In [8]: df.tz_localize('UTC')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-fa0ae4582d5d> in <module>()
----> 1 df.tz_localize('UTC')
/Users/mtrbean/.virtualenvs/stats/lib/python2.7/site-packages/pandas/core/generic.pyc in tz_localize(self, tz, axis, copy, infer_dst)
3492 ax_name = self._get_axis_name(axis)
3493 raise TypeError('%s is not a valid DatetimeIndex or PeriodIndex' %
-> 3494 ax_name)
3495 else:
3496 ax = DatetimeIndex([],tz=tz)
TypeError: index is not a valid DatetimeIndex or PeriodIndex