Skip to content

BUG: Bug in multi-axis indexing with > 2 ndim and a multi-index (GH7199) #7202

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 22, 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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ Bug Fixes
- Bug in recognizing out-of-bounds positional list indexers with ``iloc`` and a multi-axis tuple indexer (:issue:`7189`)
- Bug in setitem with a single value, multi-index and integer indices (:issue:`7190`)
- Bug in expressions evaluation with reversed ops, showing in series-dataframe ops (:issue:`7198`, :issue:`7192`)
- Bug in multi-axis indexing with > 2 ndim and a multi-index (:issue:`7199`)

pandas 0.13.1
-------------
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,13 @@ def _getitem_nested_tuple(self, tup):
axis += 1
continue

current_ndim = obj.ndim
obj = getattr(obj, self.name)._getitem_axis(key, axis=axis, validate_iterable=True)
axis += 1

if obj.ndim < self.ndim:
# has the dim of the obj changed?
# GH 7199
if obj.ndim < current_ndim:
axis -= 1

return obj
Expand Down
32 changes: 32 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,38 @@ def f():
p.iloc[0,[True,True,True],[2]]
self.assertRaises(IndexError, f)

# GH 7199
# Panel with multi-index
multi_index = pd.MultiIndex.from_tuples([('ONE', 'one'),
('TWO', 'two'),
('THREE', 'three')],
names=['UPPER', 'lower'])

simple_index = [x[0] for x in multi_index]
wd1 = Panel(items=['First', 'Second'],
major_axis=['a', 'b', 'c', 'd'],
minor_axis=multi_index)

wd2 = Panel(items=['First', 'Second'],
major_axis=['a', 'b', 'c', 'd'],
minor_axis=simple_index)

expected1 = wd1['First'].iloc[[True, True, True, False], [0, 2]]
result1 = wd1.iloc[0, [True, True, True, False], [0, 2]] # WRONG
assert_frame_equal(result1,expected1)

expected2 = wd2['First'].iloc[[True, True, True, False], [0, 2]]
result2 = wd2.iloc[0, [True, True, True, False], [0, 2]]
assert_frame_equal(result2,expected2)

expected1 = DataFrame(index=['a'],columns=multi_index,dtype='float64')
result1 = wd1.iloc[0,[0],[0,1,2]]
assert_frame_equal(result1,expected1)

expected2 = DataFrame(index=['a'],columns=simple_index,dtype='float64')
result2 = wd2.iloc[0,[0],[0,1,2]]
assert_frame_equal(result2,expected2)

def test_iloc_getitem_doc_issue(self):

# multi axis slicing issue with single block
Expand Down