Skip to content

DatetimeIndex loses TZ awareness when pushed from / pulled to HDF5 #9270

Closed
@eoincondron

Description

@eoincondron

I found that when retrieving a DataFrame which had a MultiIndex containing a DatetimeIndex from a HDFStore, the TZ awareness was somehow lost.
Here is a demonstration:

import datetime as dt
import pandas as pd
start, end = dt.datetime(2015, 1, 16, 8), dt.datetime(2015, 1, 16, 17)
times = pd.date_range(start, end, freq='60min',  tz='US/Eastern')
mix = pd.MultiIndex.from_arrays([2*range(5), times])
df = pd.DataFrame(1, index= mix, columns =range(3))
df

0   1   2
0   2015-01-16 08:00:00-05:00   1   1   1
1   2015-01-16 09:00:00-05:00   1   1   1
2   2015-01-16 10:00:00-05:00   1   1   1

So far so good. Now push and pull from HDFStore:

store = pd.HDFStore('test')
store['test'] = df.swaplevel(0, 1)
store['test']
        0   1   2
2015-01-16 13:00:00 0   1   1   1
2015-01-16 14:00:00 1   1   1   1
2015-01-16 15:00:00 2   1   1   1
store['test'].index.get_level_values(1).tz is None
True

The TZ awareness is gone. A minor issue but I thought I would bring it up. Note that this happens regardless of the order of the index levels and that there is no problem in the case of a single index.and

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions