|
4 | 4 | import pandas as pd
|
5 | 5 | from pandas import (
|
6 | 6 | CategoricalIndex,
|
| 7 | + DataFrame, |
7 | 8 | Index,
|
8 | 9 | IntervalIndex,
|
9 | 10 | MultiIndex,
|
@@ -548,6 +549,15 @@ def test_intersection_with_missing_values_on_both_sides(nulls_fixture):
|
548 | 549 | tm.assert_index_equal(result, expected)
|
549 | 550 |
|
550 | 551 |
|
| 552 | +def test_union_with_missing_values_on_both_sides(nulls_fixture): |
| 553 | + # GH#38623 |
| 554 | + mi1 = MultiIndex.from_arrays([[1, nulls_fixture]]) |
| 555 | + mi2 = MultiIndex.from_arrays([[1, nulls_fixture, 3]]) |
| 556 | + result = mi1.union(mi2) |
| 557 | + expected = MultiIndex.from_arrays([[1, 3, nulls_fixture]]) |
| 558 | + tm.assert_index_equal(result, expected) |
| 559 | + |
| 560 | + |
551 | 561 | @pytest.mark.parametrize("dtype", ["float64", "Float64"])
|
552 | 562 | @pytest.mark.parametrize("sort", [None, False])
|
553 | 563 | def test_union_nan_got_duplicated(dtype, sort):
|
@@ -651,7 +661,6 @@ def test_union_keep_dtype_precision(any_real_numeric_dtype):
|
651 | 661 |
|
652 | 662 | def test_union_keep_ea_dtype_with_na(any_numeric_ea_dtype):
|
653 | 663 | # GH#48498
|
654 |
| - |
655 | 664 | arr1 = Series([4, pd.NA], dtype=any_numeric_ea_dtype)
|
656 | 665 | arr2 = Series([1, pd.NA], dtype=any_numeric_ea_dtype)
|
657 | 666 | midx = MultiIndex.from_arrays([arr1, [2, 1]], names=["a", None])
|
@@ -695,3 +704,12 @@ def test_intersection_keep_ea_dtypes(val, any_numeric_ea_dtype):
|
695 | 704 | result = midx.intersection(midx2)
|
696 | 705 | expected = MultiIndex.from_arrays([Series([2], dtype=any_numeric_ea_dtype), [1]])
|
697 | 706 | tm.assert_index_equal(result, expected)
|
| 707 | + |
| 708 | + |
| 709 | +def test_union_with_na_when_constructing_dataframe(): |
| 710 | + # GH43222 |
| 711 | + series1 = Series((1,), index=MultiIndex.from_tuples(((None, None),))) |
| 712 | + series2 = Series((10, 20), index=MultiIndex.from_tuples(((None, None), ("a", "b")))) |
| 713 | + result = DataFrame([series1, series2]) |
| 714 | + expected = DataFrame({(np.nan, np.nan): [1.0, 10.0], ("a", "b"): [np.nan, 20.0]}) |
| 715 | + tm.assert_frame_equal(result, expected) |
0 commit comments