Skip to content

Commit 789fa59

Browse files
committed
BUG: preserve DatetimeIndex.name in HDFStore/read_hdf() with tz (pandas-dev#13884)
1 parent e2cb799 commit 789fa59

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/source/whatsnew/v0.19.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ Bug Fixes
858858
- Bug in ``isnull`` ``notnull`` raise ``TypeError`` if input datetime-like has other unit than ``ns`` (:issue:`13389`)
859859
- Bug in ``.merge`` may raise ``TypeError`` if input datetime-like has other unit than ``ns`` (:issue:`13389`)
860860

861-
861+
- Bug in ``HDFStore``/``read_hdf()`` discarded ``DatetimeIndex.name`` if ``tz`` was set (:issue:`13884`)
862862

863863
- Bug in ``Categorical.remove_unused_categories()`` changes ``.codes`` dtype to platform int (:issue:`13261`)
864864
- Bug in ``groupby`` with ``as_index=False`` returns all NaN's when grouping on multiple columns including a categorical one (:issue:`13204`)

pandas/io/pytables.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4339,9 +4339,10 @@ def _set_tz(values, tz, preserve_UTC=False, coerce=False):
43394339
coerce : if we do not have a passed timezone, coerce to M8[ns] ndarray
43404340
"""
43414341
if tz is not None:
4342+
name = getattr(values, 'name', None)
43424343
values = values.ravel()
43434344
tz = tslib.get_timezone(_ensure_decoded(tz))
4344-
values = DatetimeIndex(values)
4345+
values = DatetimeIndex(values, name=name)
43454346
if values.tz is None:
43464347
values = values.tz_localize('UTC').tz_convert(tz)
43474348
if preserve_UTC:

pandas/io/tests/test_pytables.py

+12
Original file line numberDiff line numberDiff line change
@@ -2862,6 +2862,18 @@ def test_store_index_name(self):
28622862
recons = store['frame']
28632863
assert(recons.index.name == 'foo')
28642864

2865+
def test_store_index_name_with_tz(self):
2866+
# GH 13884
2867+
df = pd.DataFrame({'A': [1, 2]})
2868+
df.index = pd.DatetimeIndex([1234567890123456787, 1234567890123456788])
2869+
df.index = df.index.tz_localize('UTC')
2870+
df.index.name = 'foo'
2871+
2872+
with ensure_clean_store(self.path) as store:
2873+
store.put('frame', df, format='table')
2874+
recons = store['frame']
2875+
assert(recons.index.name == 'foo')
2876+
28652877
def test_store_series_name(self):
28662878
df = tm.makeDataFrame()
28672879
series = df['A']

0 commit comments

Comments
 (0)