From e9448f8a4d58450bdafb7fb6e9e8847c97994348 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Tue, 23 Dec 2014 21:03:21 -0500 Subject: [PATCH] BUG: Bug in Panel indexing with an object-like (GH9140) --- doc/source/whatsnew/v0.16.0.txt | 2 +- pandas/core/panel.py | 2 +- pandas/tests/test_indexing.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.16.0.txt b/doc/source/whatsnew/v0.16.0.txt index d7de5a7ac5979..14427dd8c453f 100644 --- a/doc/source/whatsnew/v0.16.0.txt +++ b/doc/source/whatsnew/v0.16.0.txt @@ -56,7 +56,7 @@ Bug Fixes .. _whatsnew_0160.bug_fixes: - Fixed compatibility issue in ``DatetimeIndex`` affecting architectures where ``numpy.int_`` defaults to ``numpy.int32`` (:issue:`8943`) - +- Bug in Panel indexing with an object-like (:issue:`9140`) diff --git a/pandas/core/panel.py b/pandas/core/panel.py index c35eb3f88bc4a..df3e6c0195be3 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -253,7 +253,7 @@ 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) - if lib.isscalar(key): + if not (_is_list_like(key) or isinstance(key, slice)): return super(Panel, self).__getitem__(key) return self.ix[key] diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 8e2e6e612a1a3..c2d5910e7859f 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -2448,6 +2448,22 @@ def test_panel_getitem(self): result = panel.ix[['ItemA','ItemB']] tm.assert_panel_equal(result,expected) + # with an object-like + # GH 9140 + class TestObject: + def __str__(self): + return "TestObject" + + obj = TestObject() + + p = Panel(np.random.randn(1,5,4), items=[obj], + major_axis = date_range('1/1/2000', periods=5), + minor_axis=['A', 'B', 'C', 'D']) + + expected = p.iloc[0] + result = p[obj] + tm.assert_frame_equal(result, expected) + def test_panel_setitem(self): # GH 7763