|
77 | 77 | is_float_dtype,
|
78 | 78 | is_hashable,
|
79 | 79 | is_integer,
|
80 |
| - is_integer_dtype, |
81 | 80 | is_interval_dtype,
|
82 | 81 | is_iterator,
|
83 | 82 | is_list_like,
|
@@ -2963,20 +2962,7 @@ def union(self, other, sort=None):
|
2963 | 2962 | stacklevel=2,
|
2964 | 2963 | )
|
2965 | 2964 |
|
2966 |
| - dtype = find_common_type([self.dtype, other.dtype]) |
2967 |
| - if self._is_numeric_dtype and other._is_numeric_dtype: |
2968 |
| - # Right now, we treat union(int, float) a bit special. |
2969 |
| - # See https://github.com/pandas-dev/pandas/issues/26778 for discussion |
2970 |
| - # We may change union(int, float) to go to object. |
2971 |
| - # float | [u]int -> float (the special case) |
2972 |
| - # <T> | <T> -> T |
2973 |
| - # <T> | <U> -> object |
2974 |
| - if not (is_integer_dtype(self.dtype) and is_integer_dtype(other.dtype)): |
2975 |
| - dtype = np.dtype("float64") |
2976 |
| - else: |
2977 |
| - # one is int64 other is uint64 |
2978 |
| - dtype = np.dtype("object") |
2979 |
| - |
| 2965 | + dtype = self._find_common_type_compat(other) |
2980 | 2966 | left = self.astype(dtype, copy=False)
|
2981 | 2967 | right = other.astype(dtype, copy=False)
|
2982 | 2968 | return left.union(right, sort=sort)
|
@@ -5410,6 +5396,19 @@ def _find_common_type_compat(self, target) -> DtypeObj:
|
5410 | 5396 | return IntervalDtype(np.float64, closed=self.closed)
|
5411 | 5397 |
|
5412 | 5398 | target_dtype, _ = infer_dtype_from(target, pandas_dtype=True)
|
| 5399 | + |
| 5400 | + # special case: if one dtype is uint64 and the other a 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 | + |
5413 | 5412 | dtype = find_common_type([self.dtype, target_dtype])
|
5414 | 5413 | if dtype.kind in ["i", "u"]:
|
5415 | 5414 | # TODO: what about reversed with self being categorical?
|
|
0 commit comments