From 6406ee82c268c17ae47015239ebf97daf23de825 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Thu, 24 Nov 2016 19:51:04 +0100 Subject: [PATCH 1/3] BUG: Ensure min_itemsize is always a list Closes #11412 --- pandas/io/pytables.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index a5ef4e0688ea6..693606fdd1d32 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3315,7 +3315,7 @@ def validate_data_columns(self, data_columns, min_itemsize): # 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 @@ def write(self, obj, data_columns=None, **kwargs): 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): From b9bb88f97a14a577b797546792359bde23b7789c Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Wed, 23 Nov 2016 11:30:48 +0100 Subject: [PATCH 2/3] Tests for previous commit --- pandas/io/tests/test_pytables.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index 69a935e07bbfc..d621797558c8f 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -1362,6 +1362,16 @@ def check_col(key, name, size): [[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() From e25cd1fead953f9ae36b5eef70e40252010acbd5 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Wed, 23 Nov 2016 19:03:14 +0100 Subject: [PATCH 3/3] Whatsnew --- doc/source/whatsnew/v0.19.2.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.19.2.txt b/doc/source/whatsnew/v0.19.2.txt index fe900d0480d01..9f0034bb0497f 100644 --- a/doc/source/whatsnew/v0.19.2.txt +++ b/doc/source/whatsnew/v0.19.2.txt @@ -59,6 +59,7 @@ Bug Fixes - Bug ``HDFStore`` 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 ``index`` (:issue:`11412`) - Bug in ``Series.groupby.nunique()`` raising an ``IndexError`` for an empty ``Series`` (:issue:`12553`)