Skip to content

Commit

Permalink
BUG: Bug in Panel indexing with a list-like (GH8710)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed Nov 2, 2014
1 parent 02de853 commit 723881b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.15.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)



Expand Down
6 changes: 4 additions & 2 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 723881b

Please sign in to comment.