Skip to content

Commit 66934c2

Browse files
committed
Merge pull request #5718 from jreback/panel_hdf
BUG: In a HDFStore, correctly handle data_columns with a Panel (GH5717)
2 parents b4a166d + e6079bf commit 66934c2

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ Bug Fixes
550550
(:issue:`4708`)
551551
- Fixed decoding perf issue on pyt3 (:issue:`5441`)
552552
- Validate levels in a multi-index before storing (:issue:`5527`)
553+
- Correctly handle ``data_columns`` with a Panel (:issue:`5717`)
553554
- Fixed bug in tslib.tz_convert(vals, tz1, tz2): it could raise IndexError
554555
exception while trying to access trans[pos + 1] (:issue:`4496`)
555556
- The ``by`` argument now works correctly with the ``layout`` argument

pandas/io/pytables.py

+2
Original file line numberDiff line numberDiff line change
@@ -3446,6 +3446,8 @@ def read(self, where=None, columns=None, **kwargs):
34463446

34473447
# the data need to be sorted
34483448
sorted_values = c.take_data().take(sorter, axis=0)
3449+
if sorted_values.ndim == 1:
3450+
sorted_values = sorted_values.reshape(sorted_values.shape[0],1)
34493451

34503452
take_labels = [l.take(sorter) for l in labels]
34513453
items = Index(c.values)

pandas/io/tests/test_pytables.py

+23
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,29 @@ def check_col(key,name,size):
13501350
expected = df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == 'foo')]
13511351
tm.assert_frame_equal(result,expected)
13521352

1353+
with ensure_clean_store(self.path) as store:
1354+
# panel
1355+
# GH5717 not handling data_columns
1356+
np.random.seed(1234)
1357+
p = tm.makePanel()
1358+
1359+
store.append('p1',p)
1360+
tm.assert_panel_equal(store.select('p1'),p)
1361+
1362+
store.append('p2',p,data_columns=True)
1363+
tm.assert_panel_equal(store.select('p2'),p)
1364+
1365+
result = store.select('p2',where='ItemA>0')
1366+
expected = p.to_frame()
1367+
expected = expected[expected['ItemA']>0]
1368+
tm.assert_frame_equal(result.to_frame(),expected)
1369+
1370+
result = store.select('p2',where='ItemA>0 & minor_axis=["A","B"]')
1371+
expected = p.to_frame()
1372+
expected = expected[expected['ItemA']>0]
1373+
expected = expected[expected.reset_index(level=['major']).index.isin(['A','B'])]
1374+
tm.assert_frame_equal(result.to_frame(),expected)
1375+
13531376
def test_create_table_index(self):
13541377

13551378
with ensure_clean_store(self.path) as store:

0 commit comments

Comments
 (0)