8
8
import numpy as np
9
9
import pytest
10
10
11
- from pandas .core .dtypes .common import is_dtype_equal
11
+ from pandas .core .dtypes .cast import find_common_type
12
12
13
13
from pandas import (
14
14
CategoricalIndex ,
25
25
import pandas ._testing as tm
26
26
from pandas .api .types import (
27
27
is_datetime64tz_dtype ,
28
+ is_signed_integer_dtype ,
28
29
pandas_dtype ,
29
30
)
30
31
@@ -48,7 +49,11 @@ def test_union_different_types(index_flat, index_flat2):
48
49
idx1 = index_flat
49
50
idx2 = index_flat2
50
51
51
- type_pair = tuple (sorted ([idx1 .dtype .type , idx2 .dtype .type ], key = lambda x : str (x )))
52
+ common_dtype = find_common_type ([idx1 .dtype , idx2 .dtype ])
53
+
54
+ any_uint64 = idx1 .dtype == np .uint64 or idx2 .dtype == np .uint64
55
+ idx1_signed = is_signed_integer_dtype (idx1 .dtype )
56
+ idx2_signed = is_signed_integer_dtype (idx2 .dtype )
52
57
53
58
# Union with a non-unique, non-monotonic index raises error
54
59
# This applies to the boolean index
@@ -58,23 +63,12 @@ def test_union_different_types(index_flat, index_flat2):
58
63
res1 = idx1 .union (idx2 )
59
64
res2 = idx2 .union (idx1 )
60
65
61
- if is_dtype_equal (idx1 .dtype , idx2 .dtype ):
62
- assert res1 .dtype == idx1 .dtype
63
- assert res2 .dtype == idx1 .dtype
64
-
65
- elif type_pair not in COMPATIBLE_INCONSISTENT_PAIRS :
66
- # A union with a CategoricalIndex (even as dtype('O')) and a
67
- # non-CategoricalIndex can only be made if both indices are monotonic.
68
- # This is true before this PR as well.
66
+ if any_uint64 and (idx1_signed or idx2_signed ):
69
67
assert res1 .dtype == np .dtype ("O" )
70
68
assert res2 .dtype == np .dtype ("O" )
71
-
72
- elif idx1 .dtype .kind in ["f" , "i" , "u" ] and idx2 .dtype .kind in ["f" , "i" , "u" ]:
73
- assert res1 .dtype == np .dtype ("f8" )
74
- assert res2 .dtype == np .dtype ("f8" )
75
-
76
69
else :
77
- raise NotImplementedError
70
+ assert res1 .dtype == common_dtype
71
+ assert res2 .dtype == common_dtype
78
72
79
73
80
74
@pytest .mark .parametrize (
0 commit comments