@@ -1573,7 +1573,6 @@ def test_is_(self):
1573
1573
# shouldn't change
1574
1574
assert mi2 .is_ (mi )
1575
1575
mi4 = mi3 .view ()
1576
- # GH 17464 - Remove duplicate MultiIndex levels
1577
1576
mi4 .set_levels ([lrange (10 ), lrange (10 )], inplace = True )
1578
1577
assert not mi4 .is_ (mi3 )
1579
1578
mi5 = mi .view ()
@@ -2376,7 +2375,6 @@ def test_level_setting_resets_attributes(self):
2376
2375
['A' , 'A' , 'B' , 'B' , 'B' ], [1 , 2 , 1 , 2 , 3 ]
2377
2376
])
2378
2377
assert ind .is_monotonic
2379
- # GH 17464 - Remove duplicate MultiIndex levels
2380
2378
ind .set_levels ([['A' , 'B' ], [1 , 3 , 2 ]], inplace = True )
2381
2379
# if this fails, probably didn't reset the cache correctly.
2382
2380
assert not ind .is_monotonic
@@ -2980,3 +2978,15 @@ def test_nan_stays_float(self):
2980
2978
assert pd .isna (df0 .index .get_level_values (1 )).all ()
2981
2979
# the following failed in 0.14.1
2982
2980
assert pd .isna (dfm .index .get_level_values (1 )[:- 1 ]).all ()
2981
+
2982
+ def test_duplicate_multiindex_labels (self ):
2983
+ # GH 17464
2984
+ # Make sure that a MultiIndex with duplicate levels throws a ValueError
2985
+ with pytest .raises (ValueError ):
2986
+ ind = pd .MultiIndex ([['A' ] * 10 , range (10 )], [[0 ] * 10 , range (10 )])
2987
+ # And that using set_levels with duplicate levels fails
2988
+ ind = MultiIndex .from_arrays ([['A' , 'A' , 'B' , 'B' , 'B' ],
2989
+ [1 , 2 , 1 , 2 , 3 ]])
2990
+ with pytest .raises (ValueError ):
2991
+ ind .set_levels ([['A' , 'B' , 'A' , 'A' , 'B' ], [2 , 1 , 3 , - 2 , 5 ]],
2992
+ inplace = True )
0 commit comments