Skip to content

Commit ab5e8e2

Browse files
Terji PetersenTerji Petersen
Terji Petersen
authored and
Terji Petersen
committed
DEPR: don't make Index instantiate Int64/Uint64/Flaot64Index
1 parent 90b2128 commit ab5e8e2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pandas/tests/indexes/multi/test_setops.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
Series,
1111
)
1212
import pandas._testing as tm
13+
from pandas.api.types import (
14+
is_float_dtype,
15+
is_unsigned_integer_dtype,
16+
)
1317

1418

1519
@pytest.mark.parametrize("case", [0.5, "xxx"])
@@ -624,14 +628,24 @@ def test_union_duplicates(index, request):
624628
expected = mi2.sort_values()
625629
tm.assert_index_equal(result, expected)
626630

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+
):
628635
# GH#47294 - union uses lib.fast_zip, converting data to Python integers
629636
# and loses type information. Result is then unsigned only when values are
630637
# sufficiently large to require unsigned dtype. This happens only if other
631638
# has dups or one of both have missing values
632639
expected = expected.set_levels(
633640
[expected.levels[0].astype(int), expected.levels[1]]
634641
)
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+
635649
result = mi1.union(mi2)
636650
tm.assert_index_equal(result, expected)
637651

0 commit comments

Comments
 (0)