diff --git a/doc/source/whatsnew/v0.19.2.txt b/doc/source/whatsnew/v0.19.2.txt index cafbdb731f494..130653441fc0d 100644 --- a/doc/source/whatsnew/v0.19.2.txt +++ b/doc/source/whatsnew/v0.19.2.txt @@ -58,7 +58,7 @@ Bug Fixes - +- Bug ``HDFStore`` writing a ``MultiIndex`` when using ``data_columns=True`` (:issue:`14435`) - Bug in clipboard functions on linux with python2 with unicode and separators (:issue:`13747`) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index b8c2b146b6259..a5ef4e0688ea6 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -4254,7 +4254,7 @@ def write(self, obj, data_columns=None, **kwargs): if data_columns is None: data_columns = [] elif data_columns is True: - data_columns = obj.columns[:] + data_columns = obj.columns.tolist() obj, self.levels = self.validate_multiindex(obj) for n in self.levels: if n not in data_columns: diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index 72973105ff3bd..fe20eeda16ce2 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -1818,6 +1818,19 @@ def test_select_columns_in_where(self): store.put('s', s, format='table') tm.assert_series_equal(store.select('s', where="columns=['A']"), s) + def test_mi_data_columns(self): + # GH 14435 + idx = pd.MultiIndex.from_arrays([date_range('2000-01-01', periods=5), + range(5)], names=['date', 'id']) + df = pd.DataFrame({'a': [1.1, 1.2, 1.3, 1.4, 1.5]}, index=idx) + + with ensure_clean_store(self.path) as store: + store.append('df', df, data_columns=True) + + actual = store.select('df', where='id == 1') + expected = df.iloc[[1], :] + tm.assert_frame_equal(actual, expected) + def test_pass_spec_to_storer(self): df = tm.makeDataFrame()