Skip to content

Commit

Permalink
BUG: get_indexer for MultiIndex does not raise Exception for non-unique
Browse files Browse the repository at this point in the history
  • Loading branch information
changhiskhan committed Nov 2, 2012
1 parent 669c606 commit 3a8b0f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,10 @@ def get_indexer(self, target, method=None, limit=None):
if target_index.dtype != object:
return np.ones(len(target_index)) * -1

if not self.is_unique:
raise Exception('Reindexing only valid with uniquely valued Index '
'objects')

self_index = self._tuple_index

if method == 'pad':
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4339,6 +4339,21 @@ def test_drop_col_still_multiindex(self):
del df[('a','','')]
assert(isinstance(df.columns, MultiIndex))

def test_drop_nonuq_multiindex(self):
df = DataFrame([["x-a", "x", "a", 1.5],["x-a", "x", "a", 1.2],
["z-c", "z", "c", 3.1], ["x-a", "x", "a", 4.1],
["x-b", "x", "b", 5.1],["x-b", "x", "b", 4.1],
["x-b", "x", "b", 2.2],
["y-a", "y", "a", 1.2],["z-b", "z", "b", 2.1]],
columns=["var1", "var2", "var3", "var4"])

grp_size = df.groupby("var1").size()
drop_idx = grp_size.ix[grp_size == 1]

df = df.set_index(["var1", "var2", "var3"])

self.assertRaises(Exception, df.drop, drop_idx.index, level=0)

def test_fillna(self):
self.tsframe['A'][:5] = nan
self.tsframe['A'][-5:] = nan
Expand Down

0 comments on commit 3a8b0f8

Please sign in to comment.