Skip to content

Commit e568a5a

Browse files
committed
Added test to make sure a ValueError is thrown
1 parent cd6a45b commit e568a5a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pandas/tests/indexes/test_multi.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -2456,11 +2456,6 @@ def test_level_setting_resets_attributes(self):
24562456
['A', 'A', 'B', 'B', 'B'], [1, 2, 1, 2, 3]
24572457
])
24582458
assert ind.is_monotonic
2459-
<<<<<<< HEAD
2460-
2461-
# GH 17464 - Remove duplicate MultiIndex levels
2462-
=======
2463-
>>>>>>> 6ce2637... Removed comments about this issue from other tests
24642459
ind.set_levels([['A', 'B'], [1, 3, 2]], inplace=True)
24652460
# if this fails, probably didn't reset the cache correctly.
24662461
assert not ind.is_monotonic
@@ -3088,3 +3083,14 @@ def test_million_record_attribute_error(self):
30883083
with tm.assert_raises_regex(AttributeError,
30893084
"'Series' object has no attribute 'foo'"):
30903085
df['a'].foo()
3086+
3087+
def test_duplicate_multiindex_labels(self):
3088+
# GH 17464
3089+
# Make sure that a MultiIndex with duplicate levels throws a ValueError
3090+
with pytest.raises(ValueError):
3091+
ind = pd.MultiIndex([['A'] * 10, range(10)], [[0] * 10, range(10)])
3092+
# And that using set_levels with duplicate levels fails
3093+
ind = MultiIndex.from_arrays([['A', 'A', 'B', 'B', 'B'], [1, 2, 1, 2, 3]])
3094+
with pytest.raises(ValueError):
3095+
ind.set_levels([['A', 'B', 'A', 'A', 'B'], [2, 1, 3, -2, 5]],
3096+
inplace=True)

0 commit comments

Comments
 (0)