Skip to content

BUG: (GH3617) Fix indexing issue with ndim >= 3 with iloc #3618

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
May 16, 2013
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: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pandas 0.11.1
- Fix incorrect dtype on groupby with ``as_index=False`` (GH3610_)
- Fix ``read_csv`` to correctly encode identical na_values, e.g. ``na_values=[-999.0,-999]``
was failing (GH3611_)
- Fix indexing issue in ndim >= 3 with ``iloc`` (GH3617_)

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH2786: https://github.com/pydata/pandas/issues/2786
Expand Down Expand Up @@ -167,6 +168,7 @@ pandas 0.11.1
.. _GH3590: https://github.com/pydata/pandas/issues/3590
.. _GH3610: https://github.com/pydata/pandas/issues/3610
.. _GH3596: https://github.com/pydata/pandas/issues/3596
.. _GH3617: https://github.com/pydata/pandas/issues/3617
.. _GH3435: https://github.com/pydata/pandas/issues/3435
.. _GH3611: https://github.com/pydata/pandas/issues/3611

Expand Down
8 changes: 8 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,16 @@ def _has_valid_type(self, key, axis):
def _getitem_tuple(self, tup):

self._has_valid_tuple(tup)
try:
return self._getitem_lowerdim(tup)
except:
pass

retval = self.obj
for i, key in enumerate(tup):
if i >= self.obj.ndim:
raise IndexingError('Too many indexers')

if _is_null_slice(key):
continue

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _init_arrays(self, arrays, arr_names, axes):

@property
def shape(self):
return [len(getattr(self, a)) for a in self._AXIS_ORDERS]
return tuple([len(getattr(self, a)) for a in self._AXIS_ORDERS])

@classmethod
def from_dict(cls, data, intersect=False, orient='items', dtype=None):
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,19 @@ def test_set_index_nan(self):
result = df.set_index(['year','PRuid','QC']).reset_index().reindex(columns=df.columns)
assert_frame_equal(result,df)

def test_iloc_panel_issue(self):

# GH 3617
p = Panel(randn(4, 4, 4))

self.assert_(p.iloc[:3, :3, :3].shape == (3,3,3))
self.assert_(p.iloc[1, :3, :3].shape == (3,3))
self.assert_(p.iloc[:3, 1, :3].shape == (3,3))
self.assert_(p.iloc[:3, :3, 1].shape == (3,3))
self.assert_(p.iloc[1, 1, :3].shape == (3,))
self.assert_(p.iloc[1, :3, 1].shape == (3,))
self.assert_(p.iloc[:3, 1, 1].shape == (3,))


if __name__ == '__main__':
import nose
Expand Down