Skip to content

Commit

Permalink
BUG: preserve index names in MultiIndex.drop, close #1513
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Jun 22, 2012
1 parent 44a8295 commit 836ecab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,8 @@ def delete(self, loc):
new_index : MultiIndex
"""
new_labels = [np.delete(lab, loc) for lab in self.labels]
return MultiIndex(levels=self.levels, labels=new_labels)
return MultiIndex(levels=self.levels, labels=new_labels,
names=self.names)

get_major_bounds = slice_locs

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 @@ -1355,6 +1355,16 @@ def test_drop_level(self):
expected = self.frame.ix[[0, 2, 3, 6, 7, 9]].T
assert_frame_equal(result, expected)

def test_drop_preserve_names(self):
index = MultiIndex.from_arrays([[0, 0, 0, 1, 1, 1],
[1, 2, 3, 1, 2, 3]],
names=['one', 'two'])

df = DataFrame(np.random.randn(6, 3), index=index)

result = df.drop([(0, 2)])
self.assert_(result.index.names == ['one', 'two'])

def test_unicode_repr_issues(self):
levels = [Index([u'a/\u03c3', u'b/\u03c3',u'c/\u03c3']),
Index([0, 1])]
Expand Down

0 comments on commit 836ecab

Please sign in to comment.