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