|
2 | 2 | import pytest
|
3 | 3 |
|
4 | 4 | import pandas as pd
|
5 |
| -from pandas import Index, MultiIndex, Series |
| 5 | +from pandas import Index, MultiIndex, Series, IntervalIndex, CategoricalIndex |
6 | 6 | import pandas._testing as tm
|
7 | 7 |
|
8 | 8 |
|
@@ -483,3 +483,24 @@ def test_intersection_different_names():
|
483 | 483 | mi2 = MultiIndex.from_arrays([[1], [3]])
|
484 | 484 | result = mi.intersection(mi2)
|
485 | 485 | 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