Skip to content

Commit daa7265

Browse files
committed
Merge pull request #8715 from jreback/panel_index
BUG: Bug in Panel indexing with a list-like (GH8710)
2 parents 02de853 + 723881b commit daa7265

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

doc/source/whatsnew/v0.15.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Bug Fixes
188188
- Bug in groupby-transform with a Categorical (:issue:`8623`)
189189
- Bug in duplicated/drop_duplicates with a Categorical (:issue:`8623`)
190190
- Bug in ``Categorical`` reflected comparison operator raising if the first argument was a numpy array scalar (e.g. np.int64) (:issue:`8658`)
191-
191+
- Bug in Panel indexing with a list-like (:issue:`8710`)
192192

193193

194194

pandas/core/panel.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import pandas.core.ops as ops
3030
import pandas.core.nanops as nanops
3131
import pandas.computation.expressions as expressions
32-
32+
from pandas import lib
3333

3434
_shared_doc_kwargs = dict(
3535
axes='items, major_axis, minor_axis',
@@ -253,7 +253,9 @@ def from_dict(cls, data, intersect=False, orient='items', dtype=None):
253253
def __getitem__(self, key):
254254
if isinstance(self._info_axis, MultiIndex):
255255
return self._getitem_multilevel(key)
256-
return super(Panel, self).__getitem__(key)
256+
if lib.isscalar(key):
257+
return super(Panel, self).__getitem__(key)
258+
return self.ix[key]
257259

258260
def _getitem_multilevel(self, key):
259261
info = self._info_axis

pandas/tests/test_indexing.py

+24
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,30 @@ def test_panel_getitem(self):
23252325
test1 = panel.ix[:, "2002"]
23262326
tm.assert_panel_equal(test1,test2)
23272327

2328+
# GH8710
2329+
# multi-element getting with a list
2330+
panel = tm.makePanel()
2331+
2332+
expected = panel.iloc[[0,1]]
2333+
2334+
result = panel.loc[['ItemA','ItemB']]
2335+
tm.assert_panel_equal(result,expected)
2336+
2337+
result = panel.loc[['ItemA','ItemB'],:,:]
2338+
tm.assert_panel_equal(result,expected)
2339+
2340+
result = panel[['ItemA','ItemB']]
2341+
tm.assert_panel_equal(result,expected)
2342+
2343+
result = panel.loc['ItemA':'ItemB']
2344+
tm.assert_panel_equal(result,expected)
2345+
2346+
result = panel.ix['ItemA':'ItemB']
2347+
tm.assert_panel_equal(result,expected)
2348+
2349+
result = panel.ix[['ItemA','ItemB']]
2350+
tm.assert_panel_equal(result,expected)
2351+
23282352
def test_panel_setitem(self):
23292353

23302354
# GH 7763

0 commit comments

Comments
 (0)