BUG: Ensure min_itemsize is always a list (#11412)

closes #11412

Author: Pietro Battiston <me@pietrobattiston.it>

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

(cherry picked from commit 53bf1b27c7)
This commit is contained in:
Pietro Battiston 2016-12-05 18:42:02 -05:00 committed by Joris Van den Bossche
parent 36dad8418f
commit 90e19223af
3 changed files with 14 additions and 3 deletions

View File

@ -58,7 +58,8 @@ Bug Fixes
- Bug ``HDFStore`` writing a ``MultiIndex`` when using ``data_columns=True`` (:issue:`14435`)
- Bug in ``HDFStore`` when writing a ``MultiIndex`` when using ``data_columns=True`` (:issue:`14435`)
- Bug in ``HDFStore.append()`` when writing a ``Series`` and passing a ``min_itemsize`` argument containing a value for the ``index`` (:issue:`11412`)
- Bug in ``Series.groupby.nunique()`` raising an ``IndexError`` for an empty ``Series`` (:issue:`12553`)

View File

@ -3315,7 +3315,7 @@ class Table(Fixed):
# evaluate the passed data_columns, True == use all columns
# take only valide axis labels
if data_columns is True:
data_columns = axis_labels
data_columns = list(axis_labels)
elif data_columns is None:
data_columns = []
@ -4153,7 +4153,7 @@ class AppendableSeriesTable(AppendableFrameTable):
obj = DataFrame({name: obj}, index=obj.index)
obj.columns = [name]
return super(AppendableSeriesTable, self).write(
obj=obj, data_columns=obj.columns, **kwargs)
obj=obj, data_columns=obj.columns.tolist(), **kwargs)
def read(self, columns=None, **kwargs):

View File

@ -1362,6 +1362,16 @@ class TestHDFStore(Base, tm.TestCase):
[[124, 'abcdefqhij'], [346, 'abcdefghijklmnopqrtsuvwxyz']])
self.assertRaises(ValueError, store.append, 'df_new', df_new)
# min_itemsize on Series index (GH 11412)
df = tm.makeMixedDataFrame().set_index('C')
store.append('ss', df['B'], min_itemsize={'index': 4})
tm.assert_series_equal(store.select('ss'), df['B'])
# same as above, with data_columns=True
store.append('ss2', df['B'], data_columns=True,
min_itemsize={'index': 4})
tm.assert_series_equal(store.select('ss2'), df['B'])
# with nans
_maybe_remove(store, 'df')
df = tm.makeTimeDataFrame()