Skip to content

Commit b26c8fc

Browse files
cmazzullojreback
authored andcommitted
Added test to make sure a ValueError is thrown
1 parent 81d9a02 commit b26c8fc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pandas/tests/indexes/test_multi.py

+11
Original file line numberDiff line numberDiff line change
@@ -2985,3 +2985,14 @@ def test_nan_stays_float(self):
29852985
assert pd.isna(df0.index.get_level_values(1)).all()
29862986
# the following failed in 0.14.1
29872987
assert pd.isna(dfm.index.get_level_values(1)[:-1]).all()
2988+
2989+
def test_duplicate_multiindex_labels(self):
2990+
# GH 17464
2991+
# Make sure that a MultiIndex with duplicate levels throws a ValueError
2992+
with pytest.raises(ValueError):
2993+
ind = pd.MultiIndex([['A'] * 10, range(10)], [[0] * 10, range(10)])
2994+
# And that using set_levels with duplicate levels fails
2995+
ind = MultiIndex.from_arrays([['A', 'A', 'B', 'B', 'B'], [1, 2, 1, 2, 3]])
2996+
with pytest.raises(ValueError):
2997+
ind.set_levels([['A', 'B', 'A', 'A', 'B'], [2, 1, 3, -2, 5]],
2998+
inplace=True)

0 commit comments

Comments
 (0)