Skip to content

Commit

Permalink
BUG: set tz on DTI from fixed format HDFStore
Browse files Browse the repository at this point in the history
Set the tz after creating the DatetimeIndex instance when reading from a fixed
format HDFStore. Setting the tz during instance creation offset data.

closes #17618
  • Loading branch information
jjhelmus committed Oct 11, 2017
1 parent 727ea20 commit a4de0cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ Indexing
I/O
^^^

- Bug in :func:`read_hdf` when reading a timezone aware index from ``fixed`` format HDFStore (:issue:`17618`)
- Bug in :func:`read_csv` in which columns were not being thoroughly de-duplicated (:issue:`17060`)
- Bug in :func:`read_csv` in which specified column names were not being thoroughly de-duplicated (:issue:`17095`)
- Bug in :func:`read_csv` in which non integer values for the header argument generated an unhelpful / unrelated error message (:issue:`16338`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2391,8 +2391,8 @@ def _alias_to_class(self, alias):
def _get_index_factory(self, klass):
if klass == DatetimeIndex:
def f(values, freq=None, tz=None):
return DatetimeIndex._simple_new(values, None, freq=freq,
tz=tz)
return _set_tz(DatetimeIndex._simple_new(values, None,
freq=freq), tz)
return f
elif klass == PeriodIndex:
def f(values, freq=None, tz=None):
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,17 @@ def test_calendar_roundtrip_issue(self):
result = store.select('table')
assert_series_equal(result, s)

def test_roundtrip_tz_aware_index(self):
# GH 17618
time = pd.Timestamp('2000-01-01 01:00:00', tz='US/Eastern')
df = pd.DataFrame(data=[0], index=[time])

with ensure_clean_store(self.path) as store:
store.put('frame', df, format='fixed')
recons = store['frame']
tm.assert_frame_equal(recons, df)
assert recons.index[0].value == 946706400000000000

def test_append_with_timedelta(self):
# GH 3577
# append timedelta
Expand Down

0 comments on commit a4de0cf

Please sign in to comment.