Skip to content

Commit 0926b2d

Browse files
jjhelmusjreback
authored andcommitted
BUG: set tz on DTI from fixed format HDFStore (#17844)
closes #17618
1 parent c277cd7 commit 0926b2d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Diff for: doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ Indexing
941941
I/O
942942
^^^
943943

944+
- Bug in :func:`read_hdf` when reading a timezone aware index from ``fixed`` format HDFStore (:issue:`17618`)
944945
- Bug in :func:`read_csv` in which columns were not being thoroughly de-duplicated (:issue:`17060`)
945946
- Bug in :func:`read_csv` in which specified column names were not being thoroughly de-duplicated (:issue:`17095`)
946947
- Bug in :func:`read_csv` in which non integer values for the header argument generated an unhelpful / unrelated error message (:issue:`16338`)

Diff for: pandas/io/pytables.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2391,8 +2391,11 @@ 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+
# data are already in UTC, localize and convert if tz present
2395+
result = DatetimeIndex._simple_new(values, None, freq=freq)
2396+
if tz is not None:
2397+
result = result.tz_localize('UTC').tz_convert(tz)
2398+
return result
23962399
return f
23972400
elif klass == PeriodIndex:
23982401
def f(values, freq=None, tz=None):

Diff for: 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)