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

tzinfo lost when concatenating multiindex arrays #6606

Closed
sleibman opened this issue Mar 11, 2014 · 4 comments · Fixed by #7112
Closed

tzinfo lost when concatenating multiindex arrays #6606

sleibman opened this issue Mar 11, 2014 · 4 comments · Fixed by #7112
Labels
Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype
Milestone

Comments

@sleibman
Copy link

This may be related to #3950 though my symptoms are a bit different. In that issue, the tzinfo was lost during the creation of a MultiIndex array. In my case, I'm able to create a MultiIndex array with intact tzinfo, but tzinfo gets lost when I concatenate one or more such arrays.

Here's an example. Note the lack of tzinfo in the final line:

In [47]: import pandas
In [48]: import datetime
In [49]: import pytz
In [50]: array = pandas.DataFrame({'a':[datetime.datetime(2014,1,1,tzinfo=pytz.UTC), datetime.datetime(2014,1,2,tzinfo=pytz.UTC)], 'b':[1, 2], 'c':[3, 4]})
In [51]: a2 = array.set_index('a')
In [52]: a3 = array.set_index(['a', 'b'])
In [53]: a2_concatenated = pandas.concat([a2])
In [54]: a3_concatenated = pandas.concat([a3])
In [55]: array.iloc[0,0]
Out[55]: datetime.datetime(2014, 1, 1, 0, 0, tzinfo=<UTC>)
In [56]: a2.index[0]
Out[56]: Timestamp('2014-01-01 00:00:00+0000', tz='UTC')
In [57]: a3.index[0]
Out[57]: (Timestamp('2014-01-01 00:00:00+0000', tz='UTC'), 1)
In [58]: a2_concatenated.index[0]
Out[58]: Timestamp('2014-01-01 00:00:00+0000', tz='UTC')
In [59]: a3_concatenated.index[0]
Out[59]: (Timestamp('2014-01-01 00:00:00', tz=None), 1)
@sleibman
Copy link
Author

Sorry, I should have also pointed out that I am using a slightly old version:

In [60]: pandas.__version__
Out[60]: '0.12.0'

I have not yet tested with any 0.13 versions.

@dsm054
Copy link
Contributor

dsm054 commented Mar 11, 2014

I can reproduce in 0.13.1-395-g391ed32.

@jreback jreback added this to the 0.14.0 milestone Mar 11, 2014
@jreback
Copy link
Contributor

jreback commented Mar 11, 2014

@sleibman if you or @dsm054 would like to take a stab would be appreciated!

@sleibman
Copy link
Author

I may be able to supply a fix but haven't dug into the underlying code yet.
An additional observation: Even just calling reset_index() on a MultiIndex array causes the tz offset to disappear:

In [70]: a3
Out[70]: 
                             c
a                         b   
2014-01-01 00:00:00+00:00 1  3
2014-01-02 00:00:00+00:00 2  4

In [71]: a3.reset_index()
Out[71]: 
                    a  b  c
0 2014-01-01 00:00:00  1  3
1 2014-01-02 00:00:00  2  4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants