diff --git a/doc/source/release.rst b/doc/source/release.rst index d5163b9dbc60b..5ce9ccd25a7fc 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -550,6 +550,7 @@ Bug Fixes (:issue:`4708`) - Fixed decoding perf issue on pyt3 (:issue:`5441`) - Validate levels in a multi-index before storing (:issue:`5527`) + - Correctly handle ``data_columns`` with a Panel (:issue:`5717`) - Fixed bug in tslib.tz_convert(vals, tz1, tz2): it could raise IndexError exception while trying to access trans[pos + 1] (:issue:`4496`) - The ``by`` argument now works correctly with the ``layout`` argument diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 09618b77a2968..bc99417c67310 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3446,6 +3446,8 @@ def read(self, where=None, columns=None, **kwargs): # the data need to be sorted sorted_values = c.take_data().take(sorter, axis=0) + if sorted_values.ndim == 1: + sorted_values = sorted_values.reshape(sorted_values.shape[0],1) take_labels = [l.take(sorter) for l in labels] items = Index(c.values) diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index e9c04932aba40..c9955b1ae2fb2 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -1350,6 +1350,29 @@ def check_col(key,name,size): expected = df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == 'foo')] tm.assert_frame_equal(result,expected) + with ensure_clean_store(self.path) as store: + # panel + # GH5717 not handling data_columns + np.random.seed(1234) + p = tm.makePanel() + + store.append('p1',p) + tm.assert_panel_equal(store.select('p1'),p) + + store.append('p2',p,data_columns=True) + tm.assert_panel_equal(store.select('p2'),p) + + result = store.select('p2',where='ItemA>0') + expected = p.to_frame() + expected = expected[expected['ItemA']>0] + tm.assert_frame_equal(result.to_frame(),expected) + + result = store.select('p2',where='ItemA>0 & minor_axis=["A","B"]') + expected = p.to_frame() + expected = expected[expected['ItemA']>0] + expected = expected[expected.reset_index(level=['major']).index.isin(['A','B'])] + tm.assert_frame_equal(result.to_frame(),expected) + def test_create_table_index(self): with ensure_clean_store(self.path) as store: