diff --git a/doc/source/whatsnew/v0.15.1.txt b/doc/source/whatsnew/v0.15.1.txt index 343c6451d15ac..a0aa1ca2716fc 100644 --- a/doc/source/whatsnew/v0.15.1.txt +++ b/doc/source/whatsnew/v0.15.1.txt @@ -188,7 +188,7 @@ Bug Fixes - Bug in groupby-transform with a Categorical (:issue:`8623`) - Bug in duplicated/drop_duplicates with a Categorical (:issue:`8623`) - Bug in ``Categorical`` reflected comparison operator raising if the first argument was a numpy array scalar (e.g. np.int64) (:issue:`8658`) - +- Bug in Panel indexing with a list-like (:issue:`8710`) diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 72f9c5bd00cb7..c35eb3f88bc4a 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -29,7 +29,7 @@ import pandas.core.ops as ops import pandas.core.nanops as nanops import pandas.computation.expressions as expressions - +from pandas import lib _shared_doc_kwargs = dict( axes='items, major_axis, minor_axis', @@ -253,7 +253,9 @@ def from_dict(cls, data, intersect=False, orient='items', dtype=None): def __getitem__(self, key): if isinstance(self._info_axis, MultiIndex): return self._getitem_multilevel(key) - return super(Panel, self).__getitem__(key) + if lib.isscalar(key): + return super(Panel, self).__getitem__(key) + return self.ix[key] def _getitem_multilevel(self, key): info = self._info_axis diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 7bc5ca0bfb2e7..32b27e139cc21 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -2325,6 +2325,30 @@ def test_panel_getitem(self): test1 = panel.ix[:, "2002"] tm.assert_panel_equal(test1,test2) + # GH8710 + # multi-element getting with a list + panel = tm.makePanel() + + expected = panel.iloc[[0,1]] + + result = panel.loc[['ItemA','ItemB']] + tm.assert_panel_equal(result,expected) + + result = panel.loc[['ItemA','ItemB'],:,:] + tm.assert_panel_equal(result,expected) + + result = panel[['ItemA','ItemB']] + tm.assert_panel_equal(result,expected) + + result = panel.loc['ItemA':'ItemB'] + tm.assert_panel_equal(result,expected) + + result = panel.ix['ItemA':'ItemB'] + tm.assert_panel_equal(result,expected) + + result = panel.ix[['ItemA','ItemB']] + tm.assert_panel_equal(result,expected) + def test_panel_setitem(self): # GH 7763