Skip to content

Commit 693da38

Browse files
committed
Add testcases
1 parent eab8d1f commit 693da38

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

pandas/tests/indexes/multi/test_setops.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
import pandas as pd
5-
from pandas import Index, MultiIndex, Series
5+
from pandas import Index, MultiIndex, Series, IntervalIndex, CategoricalIndex
66
import pandas._testing as tm
77

88

@@ -483,3 +483,24 @@ def test_intersection_different_names():
483483
mi2 = MultiIndex.from_arrays([[1], [3]])
484484
result = mi.intersection(mi2)
485485
tm.assert_index_equal(result, mi2)
486+
487+
488+
def test_union_nan_got_duplicated():
489+
# GH
490+
mi1 = MultiIndex.from_arrays([[1.0, np.nan], [2, 3]])
491+
mi2 = MultiIndex.from_arrays([[1.0, np.nan, 3.0], [2, 3, 4]])
492+
result = mi1.union(mi2)
493+
tm.assert_index_equal(result, mi2)
494+
495+
496+
def test_union_duplicates(index):
497+
# GH
498+
# Index has to be sorted as of now.
499+
if index.empty or isinstance(index, (IntervalIndex, CategoricalIndex)):
500+
# No duplicates in empty indexes
501+
return
502+
values = index.unique().sort_values().values.tolist()
503+
mi1 = MultiIndex.from_arrays([values, [1] * len(values)])
504+
mi2 = MultiIndex.from_arrays([[values[0]] + values, [1] * (len(values) + 1)])
505+
result = mi1.union(mi2)
506+
tm.assert_index_equal(result, mi2.sort_values())

0 commit comments

Comments
 (0)