Skip to content

Commit 2114741

Browse files
committed
Merge pull request #9143 from jreback/panel_indexing
BUG: Bug in Panel indexing with an object-like (GH9140)
2 parents 32a2c6f + e9448f8 commit 2114741

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

doc/source/whatsnew/v0.16.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Bug Fixes
5656
.. _whatsnew_0160.bug_fixes:
5757

5858
- Fixed compatibility issue in ``DatetimeIndex`` affecting architectures where ``numpy.int_`` defaults to ``numpy.int32`` (:issue:`8943`)
59-
59+
- Bug in Panel indexing with an object-like (:issue:`9140`)
6060

6161

6262

pandas/core/panel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ 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-
if lib.isscalar(key):
256+
if not (_is_list_like(key) or isinstance(key, slice)):
257257
return super(Panel, self).__getitem__(key)
258258
return self.ix[key]
259259

pandas/tests/test_indexing.py

+16
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,22 @@ def test_panel_getitem(self):
24482448
result = panel.ix[['ItemA','ItemB']]
24492449
tm.assert_panel_equal(result,expected)
24502450

2451+
# with an object-like
2452+
# GH 9140
2453+
class TestObject:
2454+
def __str__(self):
2455+
return "TestObject"
2456+
2457+
obj = TestObject()
2458+
2459+
p = Panel(np.random.randn(1,5,4), items=[obj],
2460+
major_axis = date_range('1/1/2000', periods=5),
2461+
minor_axis=['A', 'B', 'C', 'D'])
2462+
2463+
expected = p.iloc[0]
2464+
result = p[obj]
2465+
tm.assert_frame_equal(result, expected)
2466+
24512467
def test_panel_setitem(self):
24522468

24532469
# GH 7763

0 commit comments

Comments
 (0)