Skip to content

Commit

Permalink
BUG: indexing a DataFrame with MultiIndex through .ix[index, col] wit…
Browse files Browse the repository at this point in the history
…h unsorted index #2314
  • Loading branch information
changhiskhan committed Dec 1, 2012
1 parent 5d2bc24 commit 19eeff8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _getitem_lowerdim(self, tup):
# slices are unhashable
pass
except Exception, e1:
if isinstance(tup[0], slice):
if isinstance(tup[0], (slice, Index)):
raise IndexingError
try:
loc = ax0.get_loc(tup[0])
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 @@ -314,6 +314,16 @@ def test_getitem_setitem_tuple_plus_columns(self):
expected = df.ix[2000, 1, 6][['A', 'B', 'C']]
assert_series_equal(result, expected)

def test_getitem_multilevel_index_tuple_unsorted(self):
index_columns = list("abc")
df = DataFrame([[0, 1, 0, "x"], [0, 0, 1, "y"]] ,
columns=index_columns + ["data"])
df = df.set_index(index_columns)
query_index = df.index[:1]
rs = df.ix[query_index, "data"]
xp = Series(['x'], index=MultiIndex.from_tuples([(0, 1, 0)]))
assert_series_equal(rs, xp)

def test_xs(self):
xs = self.frame.xs(('bar', 'two'))
xs2 = self.frame.ix[('bar', 'two')]
Expand Down

0 comments on commit 19eeff8

Please sign in to comment.