@@ -2456,11 +2456,6 @@ def test_level_setting_resets_attributes(self):
2456
2456
['A' , 'A' , 'B' , 'B' , 'B' ], [1 , 2 , 1 , 2 , 3 ]
2457
2457
])
2458
2458
assert ind .is_monotonic
2459
- < << << << HEAD
2460
-
2461
- # GH 17464 - Remove duplicate MultiIndex levels
2462
- == == == =
2463
- >> >> >> > 6 ce2637 ... Removed comments about this issue from other tests
2464
2459
ind .set_levels ([['A' , 'B' ], [1 , 3 , 2 ]], inplace = True )
2465
2460
# if this fails, probably didn't reset the cache correctly.
2466
2461
assert not ind .is_monotonic
@@ -3088,3 +3083,14 @@ def test_million_record_attribute_error(self):
3088
3083
with tm .assert_raises_regex (AttributeError ,
3089
3084
"'Series' object has no attribute 'foo'" ):
3090
3085
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