Skip to content

BUG: Bug in Panel indexing with a list-like (GH8710) #8715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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