Skip to content

Commit 53bf1b2

Browse files
toobazjreback
authored andcommitted
BUG: Ensure min_itemsize is always a list (#11412)
closes #11412 Author: Pietro Battiston <[email protected]> Closes #14728 from toobaz/minitemsizefix and squashes the following commits: e25cd1f [Pietro Battiston] Whatsnew b9bb88f [Pietro Battiston] Tests for previous commit 6406ee8 [Pietro Battiston] BUG: Ensure min_itemsize is always a list
1 parent b3dd9ba commit 53bf1b2

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

doc/source/whatsnew/v0.19.2.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Bug Fixes
5858

5959

6060

61-
- Bug ``HDFStore`` writing a ``MultiIndex`` when using ``data_columns=True`` (:issue:`14435`)
61+
- Bug in ``HDFStore`` when writing a ``MultiIndex`` when using ``data_columns=True`` (:issue:`14435`)
62+
- Bug in ``HDFStore.append()`` when writing a ``Series`` and passing a ``min_itemsize`` argument containing a value for the ``index`` (:issue:`11412`)
6263
- Bug in ``Series.groupby.nunique()`` raising an ``IndexError`` for an empty ``Series`` (:issue:`12553`)
6364

6465

pandas/io/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3315,7 +3315,7 @@ def validate_data_columns(self, data_columns, min_itemsize):
33153315
# evaluate the passed data_columns, True == use all columns
33163316
# take only valide axis labels
33173317
if data_columns is True:
3318-
data_columns = axis_labels
3318+
data_columns = list(axis_labels)
33193319
elif data_columns is None:
33203320
data_columns = []
33213321

@@ -4153,7 +4153,7 @@ def write(self, obj, data_columns=None, **kwargs):
41534153
obj = DataFrame({name: obj}, index=obj.index)
41544154
obj.columns = [name]
41554155
return super(AppendableSeriesTable, self).write(
4156-
obj=obj, data_columns=obj.columns, **kwargs)
4156+
obj=obj, data_columns=obj.columns.tolist(), **kwargs)
41574157

41584158
def read(self, columns=None, **kwargs):
41594159

pandas/io/tests/test_pytables.py

+10
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,16 @@ def check_col(key, name, size):
13621362
[[124, 'abcdefqhij'], [346, 'abcdefghijklmnopqrtsuvwxyz']])
13631363
self.assertRaises(ValueError, store.append, 'df_new', df_new)
13641364

1365+
# min_itemsize on Series index (GH 11412)
1366+
df = tm.makeMixedDataFrame().set_index('C')
1367+
store.append('ss', df['B'], min_itemsize={'index': 4})
1368+
tm.assert_series_equal(store.select('ss'), df['B'])
1369+
1370+
# same as above, with data_columns=True
1371+
store.append('ss2', df['B'], data_columns=True,
1372+
min_itemsize={'index': 4})
1373+
tm.assert_series_equal(store.select('ss2'), df['B'])
1374+
13651375
# with nans
13661376
_maybe_remove(store, 'df')
13671377
df = tm.makeTimeDataFrame()

0 commit comments

Comments
 (0)