|
3 | 3 |
|
4 | 4 | import pandas as pd
|
5 | 5 | from pandas import (
|
| 6 | + CategoricalIndex, |
6 | 7 | Index,
|
| 8 | + IntervalIndex, |
7 | 9 | MultiIndex,
|
8 | 10 | Series,
|
9 | 11 | )
|
@@ -508,3 +510,26 @@ def test_intersection_with_missing_values_on_both_sides(nulls_fixture):
|
508 | 510 | result = mi1.intersection(mi2)
|
509 | 511 | expected = MultiIndex.from_arrays([[3.0, nulls_fixture], [1, 2]])
|
510 | 512 | tm.assert_index_equal(result, expected)
|
| 513 | + |
| 514 | + |
| 515 | +def test_union_nan_got_duplicated(): |
| 516 | + # GH#38977 |
| 517 | + mi1 = MultiIndex.from_arrays([[1.0, np.nan], [2, 3]]) |
| 518 | + mi2 = MultiIndex.from_arrays([[1.0, np.nan, 3.0], [2, 3, 4]]) |
| 519 | + result = mi1.union(mi2) |
| 520 | + tm.assert_index_equal(result, mi2) |
| 521 | + |
| 522 | + |
| 523 | +def test_union_duplicates(index): |
| 524 | + # GH#38977 |
| 525 | + if index.empty or isinstance(index, (IntervalIndex, CategoricalIndex)): |
| 526 | + # No duplicates in empty indexes |
| 527 | + return |
| 528 | + values = index.unique().values.tolist() |
| 529 | + mi1 = MultiIndex.from_arrays([values, [1] * len(values)]) |
| 530 | + mi2 = MultiIndex.from_arrays([[values[0]] + values, [1] * (len(values) + 1)]) |
| 531 | + result = mi1.union(mi2) |
| 532 | + tm.assert_index_equal(result, mi2.sort_values()) |
| 533 | + |
| 534 | + result = mi2.union(mi1) |
| 535 | + tm.assert_index_equal(result, mi2.sort_values()) |
0 commit comments