Skip to content

Commit 40c8f1a

Browse files
committed
Add unit test and whatsnew.
1 parent dbd8b4c commit 40c8f1a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

doc/source/whatsnew/v0.20.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ I/O
7070
- Bug that raised IndexError HTML-rendering an empty DataFrame (:issue:`15953`)
7171
- Bug in ``pd.read_csv()`` in which tarfile object inputs were raising an error in Python 2.x for the C engine (:issue:`16530`)
7272
- Bug where ``DataFrame.to_html()`` ignored the ``index_names`` parameter (:issue:`16493`)
73+
- Bug where ``pd.read_hdf()`` returns numpy strings for index names (:issue:`13492`)
7374

7475
- Bug in ``HDFStore.select_as_multiple()`` where start/stop arguments were not respected (:issue:`16209`)
7576

pandas/tests/io/test_pytables.py

+27
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,33 @@ def test_store_index_name_with_tz(self):
29202920
recons = store['frame']
29212921
tm.assert_frame_equal(recons, df)
29222922

2923+
def test_store_index_name_numpy_str(self):
2924+
# GH #13492
2925+
idx = pd.Index(pd.to_datetime([datetime.date(2000, 1, 1),
2926+
datetime.date(2000, 1, 2)]),
2927+
name='cols')
2928+
idx1 = pd.Index(pd.to_datetime([datetime.date(2010, 1, 1),
2929+
datetime.date(2010, 1, 2)]),
2930+
name='rows')
2931+
df = pd.DataFrame(np.arange(4).reshape(2, 2), columns=idx, index=idx1)
2932+
2933+
# This used to fail, returning numpy strings instead of python strings.
2934+
with ensure_clean_path(self.path) as path:
2935+
df.to_hdf(path, 'df', format='fixed')
2936+
df2 = read_hdf(path, 'df')
2937+
assert_frame_equal(df, df2)
2938+
2939+
assert type(df2.index.name) == str
2940+
assert type(df2.columns.name) == str
2941+
2942+
with ensure_clean_path(self.path) as path:
2943+
df.to_hdf(path, 'df', format='table')
2944+
df2 = read_hdf(path, 'df')
2945+
assert_frame_equal(df, df2)
2946+
2947+
assert type(df2.index.name) == str
2948+
assert type(df2.columns.name) == str
2949+
29232950
def test_store_series_name(self):
29242951
df = tm.makeDataFrame()
29252952
series = df['A']

0 commit comments

Comments
 (0)