Skip to content

tz_localize() and tz_convert() doesn't work on MultiIndex #7846

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
mtrbean opened this issue Jul 26, 2014 · 5 comments · Fixed by #7915
Closed

tz_localize() and tz_convert() doesn't work on MultiIndex #7846

mtrbean opened this issue Jul 26, 2014 · 5 comments · Fixed by #7915

Comments

@mtrbean
Copy link
Contributor

mtrbean commented Jul 26, 2014

Example below for tz_localize() (Same error for tz_convert())

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
@jreback
Copy link
Contributor

jreback commented Jul 26, 2014

this is not meant to work an a MultiIndex
as it's not a defined operation

it will only work on an appropriate level (which is an DatetimeIndex/PeriodIndex)

so I could see providing a level keyword that would make this happen

interested in doing a pr?

@mtrbean
Copy link
Contributor Author

mtrbean commented Jul 26, 2014

I'd love to, and I thin it would be super easy to do with #7792 (when it is resolved).

@jreback
Copy link
Contributor

jreback commented Jul 26, 2014

gr8

want to take a stab at that issue?
only slightly more challenging

@jreback jreback added this to the 0.15.0 milestone Jul 26, 2014
@mtrbean
Copy link
Contributor Author

mtrbean commented Jul 29, 2014

sure will tackle #7792 first

@jreback
Copy link
Contributor

jreback commented Jul 30, 2014

@mtrbean alright! this should be straightfoward now after #7792

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

Successfully merging a pull request may close this issue.

2 participants