@@ -1372,6 +1372,22 @@ def check_col(key, name, size):
1372
1372
min_itemsize = {'index' : 4 })
1373
1373
tm .assert_series_equal (store .select ('ss2' ), df ['B' ])
1374
1374
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
+
1375
1391
# with nans
1376
1392
_maybe_remove (store , 'df' )
1377
1393
df = tm .makeTimeDataFrame ()
@@ -1426,6 +1442,26 @@ def check_col(key, name, size):
1426
1442
self .assertRaises (ValueError , store .append , 'df' ,
1427
1443
df , min_itemsize = {'foo' : 20 , 'foobar' : 20 })
1428
1444
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
+
1429
1465
def test_append_with_data_columns (self ):
1430
1466
1431
1467
with ensure_clean_store (self .path ) as store :
0 commit comments