Skip to content

Commit 7b69f2f

Browse files
committed
BUG: set tz on DTI from fixed format HDFStore
Set the tz after creating the DatetimeIndex instance when reading from a fixed format HDFStore. Setting the tz during instance creation offset data. closes pandas-dev#17618
1 parent 727ea20 commit 7b69f2f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pandas/io/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2391,8 +2391,8 @@ def _alias_to_class(self, alias):
23912391
def _get_index_factory(self, klass):
23922392
if klass == DatetimeIndex:
23932393
def f(values, freq=None, tz=None):
2394-
return DatetimeIndex._simple_new(values, None, freq=freq,
2395-
tz=tz)
2394+
return _set_tz(DatetimeIndex._simple_new(values, None,
2395+
freq=freq), tz)
23962396
return f
23972397
elif klass == PeriodIndex:
23982398
def f(values, freq=None, tz=None):

pandas/tests/io/test_pytables.py

+11
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,17 @@ def test_calendar_roundtrip_issue(self):
22722272
result = store.select('table')
22732273
assert_series_equal(result, s)
22742274

2275+
def test_roundtrip_tz_aware_index(self):
2276+
# GH 17618
2277+
time = pd.Timestamp('2000-01-01 01:00:00', tz='US/Eastern')
2278+
df = pd.DataFrame(data=[0], index=[time])
2279+
2280+
with ensure_clean_store(self.path) as store:
2281+
store.put('frame', df, format='fixed')
2282+
recons = store['frame']
2283+
tm.assert_frame_equal(recons, df)
2284+
assert recons.index[0].value == 946706400000000000
2285+
22752286
def test_append_with_timedelta(self):
22762287
# GH 3577
22772288
# append timedelta

0 commit comments

Comments
 (0)