@@ -2961,14 +2961,7 @@ def union(self, other, sort=None):
2961
2961
stacklevel = 2 ,
2962
2962
)
2963
2963
2964
- dtype = find_common_type ([self .dtype , other .dtype ], strict_uint64 = True )
2965
- # Right now, we treat union(float, [u]int) a bit special.
2966
- # See https://github.com/pandas-dev/pandas/issues/26778 for discussion
2967
- # Now it's:
2968
- # * float | [u]int -> float
2969
- # * uint64 | signed int -> object
2970
- # We may change union(float | [u]int) to go to object.
2971
-
2964
+ dtype = self ._find_common_type_compat (other )
2972
2965
left = self .astype (dtype , copy = False )
2973
2966
right = other .astype (dtype , copy = False )
2974
2967
return left .union (right , sort = sort )
@@ -5402,6 +5395,19 @@ def _find_common_type_compat(self, target) -> DtypeObj:
5402
5395
return IntervalDtype (np .float64 , closed = self .closed )
5403
5396
5404
5397
target_dtype , _ = infer_dtype_from (target , pandas_dtype = True )
5398
+
5399
+ # special case: if either is uint64 and other dtype is signed int, return object
5400
+ # See https://github.com/pandas-dev/pandas/issues/26778 for discussion
5401
+ # Now it's:
5402
+ # * float | [u]int -> float
5403
+ # * uint64 | signed int -> object
5404
+ # We may change union(float | [u]int) to go to object.
5405
+ if self .dtype == "uint64" or target_dtype == "uint64" :
5406
+ if is_signed_integer_dtype (self .dtype ) or is_signed_integer_dtype (
5407
+ target_dtype
5408
+ ):
5409
+ return np .dtype ("object" )
5410
+
5405
5411
dtype = find_common_type ([self .dtype , target_dtype ])
5406
5412
if dtype .kind in ["i" , "u" ]:
5407
5413
# TODO: what about reversed with self being categorical?
0 commit comments