From 5d9c7ea679069879a82c36fc891c9de1e60252b4 Mon Sep 17 00:00:00 2001 From: Daniel Waeber Date: Wed, 29 Jan 2014 10:31:51 +0100 Subject: [PATCH] BUG: fixed append for dataframe with multi-column --- doc/source/release.rst | 2 ++ pandas/io/pytables.py | 4 ++-- pandas/io/tests/test_pytables.py | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index e867f0f27a646..21ee81d4da79d 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -172,6 +172,8 @@ Bug Fixes string comparisons (:issue:`6155`). - Fixed a bug in ``query`` where the index of a single-element ``Series`` was being thrown away (:issue:`6148`). + - Bug in ``HDFStore`` on appending a dataframe with multi-indexed columns to + an existing table (:issue:`6167`) pandas 0.13.0 ------------- diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index b08be80dcb16a..bb487f5102e0a 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3068,9 +3068,9 @@ def validate_data_columns(self, data_columns, min_itemsize): axis, axis_labels = self.non_index_axes[0] info = self.info.get(axis, dict()) - if info.get('type') == 'MultiIndex' and data_columns is not None: + if info.get('type') == 'MultiIndex' and data_columns: raise ValueError("cannot use a multi-index on axis [{0}] with " - "data_columns".format(axis)) + "data_columns {1}".format(axis, data_columns)) # evaluate the passed data_columns, True == use all columns # take only valide axis labels diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index f7d01cb1bec96..9c56ee468f6ac 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -1613,6 +1613,13 @@ def test_column_multiindex(self): self.assertRaises(ValueError, store.put, 'df2',df,format='table',data_columns=['A']) self.assertRaises(ValueError, store.put, 'df3',df,format='table',data_columns=True) + # appending multi-column on existing table (see GH 6167) + with ensure_clean_store(self.path) as store: + store.append('df2', df) + store.append('df2', df) + + tm.assert_frame_equal(store['df2'], concat((df,df))) + # non_index_axes name df = DataFrame(np.arange(12).reshape(3,4), columns=Index(list('ABCD'),name='foo'))