Skip to content

Commit 38b8fcc

Browse files
committed
Tests for previous commit
1 parent c838afa commit 38b8fcc

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pandas/io/tests/test_pytables.py

+36
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,22 @@ def check_col(key, name, size):
13721372
min_itemsize={'index': 4})
13731373
tm.assert_series_equal(store.select('ss2'), df['B'])
13741374

1375+
# min_itemsize in index without appending (GH 10381)
1376+
store.put('ss3', df, format='table',
1377+
min_itemsize={'index': 6})
1378+
# just make sure there is a longer string:
1379+
df2 = df.copy().reset_index().assign(C='longer').set_index('C')
1380+
store.append('ss3', df2)
1381+
tm.assert_frame_equal(store.select('ss3'),
1382+
pd.concat([df, df2]))
1383+
1384+
# same as above, with a Series
1385+
store.put('ss4', df['B'], format='table',
1386+
min_itemsize={'index': 6})
1387+
store.append('ss4', df2['B'])
1388+
tm.assert_series_equal(store.select('ss4'),
1389+
pd.concat([df['B'], df2['B']]))
1390+
13751391
# with nans
13761392
_maybe_remove(store, 'df')
13771393
df = tm.makeTimeDataFrame()
@@ -1426,6 +1442,26 @@ def check_col(key, name, size):
14261442
self.assertRaises(ValueError, store.append, 'df',
14271443
df, min_itemsize={'foo': 20, 'foobar': 20})
14281444

1445+
def test_to_hdf_with_min_itemsize(self):
1446+
1447+
with ensure_clean_path(self.path) as path:
1448+
1449+
# min_itemsize in index with to_hdf (GH 10381)
1450+
df = tm.makeMixedDataFrame().set_index('C')
1451+
df.to_hdf(path, 'ss3', format='table', min_itemsize={'index': 6})
1452+
# just make sure there is a longer string:
1453+
df2 = df.copy().reset_index().assign(C='longer').set_index('C')
1454+
df2.to_hdf(path, 'ss3', append=True, format='table')
1455+
tm.assert_frame_equal(pd.read_hdf(path, 'ss3'),
1456+
pd.concat([df, df2]))
1457+
1458+
# same as above, with a Series
1459+
df['B'].to_hdf(path, 'ss4', format='table',
1460+
min_itemsize={'index': 6})
1461+
df2['B'].to_hdf(path, 'ss4', append=True, format='table')
1462+
tm.assert_series_equal(pd.read_hdf(path, 'ss4'),
1463+
pd.concat([df['B'], df2['B']]))
1464+
14291465
def test_append_with_data_columns(self):
14301466

14311467
with ensure_clean_store(self.path) as store:

0 commit comments

Comments
 (0)