Skip to content

Commit

Permalink
BUG: fix indexing error when selecting section of a hierarchically-in…
Browse files Browse the repository at this point in the history
…dexed DataFrame row, close #1013
  • Loading branch information
wesm committed Apr 10, 2012
1 parent 5721a0c commit 5901364
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pandas 0.7.3
**Bug fixes**

- Don't attach nonsense 'result' name to groupby results (GH #995)
- Fix logic error when selecting part of a row in a DataFrame with a
MultiIndex index (GH #1013)

pandas 0.7.2
============
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _getitem_lowerdim(self, tup):
# df.ix[d1:d2, 0] -> columns first (True)
# df.ix[0, ['C', 'B', A']] -> rows first (False)
for i, key in enumerate(tup):
if _is_label_like(key):
if _is_label_like(key) or isinstance(key, tuple):
section = self._getitem_axis(key, axis=i)

# might have been a MultiIndex
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ def test_getitem_tuple_plus_slice(self):
assert_series_equal(result, expected)
assert_series_equal(result, expected2)

def test_getitem_setitem_tuple_plus_columns(self):
# GH #1013

df = self.ymd[:5]

result = df.ix[(2000, 1, 6), ['A', 'B', 'C']]
expected = df.ix[2000, 1, 6][['A', 'B', 'C']]
assert_series_equal(result, expected)

def test_xs(self):
xs = self.frame.xs(('bar', 'two'))
xs2 = self.frame.ix[('bar', 'two')]
Expand Down Expand Up @@ -1252,6 +1261,7 @@ def test_unicode_repr_issues(self):
# NumPy bug
# repr(index.get_level_values(1))


if __name__ == '__main__':

# unittest.main()
Expand Down

0 comments on commit 5901364

Please sign in to comment.