|
10 | 10 | Series,
|
11 | 11 | )
|
12 | 12 | import pandas._testing as tm
|
| 13 | +from pandas.api.types import ( |
| 14 | + is_float_dtype, |
| 15 | + is_unsigned_integer_dtype, |
| 16 | +) |
13 | 17 |
|
14 | 18 |
|
15 | 19 | @pytest.mark.parametrize("case", [0.5, "xxx"])
|
@@ -624,14 +628,24 @@ def test_union_duplicates(index, request):
|
624 | 628 | expected = mi2.sort_values()
|
625 | 629 | tm.assert_index_equal(result, expected)
|
626 | 630 |
|
627 |
| - if mi2.levels[0].dtype == np.uint64 and (mi2.get_level_values(0) < 2**63).all(): |
| 631 | + if ( |
| 632 | + is_unsigned_integer_dtype(mi2.levels[0]) |
| 633 | + and (mi2.get_level_values(0) < 2**63).all() |
| 634 | + ): |
628 | 635 | # GH#47294 - union uses lib.fast_zip, converting data to Python integers
|
629 | 636 | # and loses type information. Result is then unsigned only when values are
|
630 | 637 | # sufficiently large to require unsigned dtype. This happens only if other
|
631 | 638 | # has dups or one of both have missing values
|
632 | 639 | expected = expected.set_levels(
|
633 | 640 | [expected.levels[0].astype(int), expected.levels[1]]
|
634 | 641 | )
|
| 642 | + elif is_float_dtype(mi2.levels[0]): |
| 643 | + # mi2 has duplicates witch is a different path than above, Fix that path |
| 644 | + # to use correct float dtype? |
| 645 | + expected = expected.set_levels( |
| 646 | + [expected.levels[0].astype(float), expected.levels[1]] |
| 647 | + ) |
| 648 | + |
635 | 649 | result = mi1.union(mi2)
|
636 | 650 | tm.assert_index_equal(result, expected)
|
637 | 651 |
|
|
0 commit comments