Skip to content

Commit 1d4ebf5

Browse files
committed
Added test to make sure a ValueError is thrown
1 parent 6ce2637 commit 1d4ebf5

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
@@ -2978,3 +2978,14 @@ def test_nan_stays_float(self):
29782978
assert pd.isna(df0.index.get_level_values(1)).all()
29792979
# the following failed in 0.14.1
29802980
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'], [1, 2, 1, 2, 3]])
2989+
with pytest.raises(ValueError):
2990+
ind.set_levels([['A', 'B', 'A', 'A', 'B'], [2, 1, 3, -2, 5]],
2991+
inplace=True)

0 commit comments

Comments
 (0)