|
15 | 15 | is_float,
|
16 | 16 | is_float_dtype,
|
17 | 17 | is_integer_dtype,
|
| 18 | + is_numeric_dtype, |
18 | 19 | is_scalar,
|
19 | 20 | is_signed_integer_dtype,
|
20 | 21 | is_unsigned_integer_dtype,
|
21 | 22 | needs_i8_conversion,
|
22 | 23 | pandas_dtype,
|
23 | 24 | )
|
24 |
| -from pandas.core.dtypes.generic import ( |
25 |
| - ABCFloat64Index, |
26 |
| - ABCInt64Index, |
27 |
| - ABCRangeIndex, |
28 |
| - ABCSeries, |
29 |
| - ABCUInt64Index, |
30 |
| -) |
| 25 | +from pandas.core.dtypes.generic import ABCSeries |
31 | 26 | from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna
|
32 | 27 |
|
33 | 28 | from pandas.core import algorithms
|
@@ -275,11 +270,9 @@ def _assert_safe_casting(cls, data, subarr):
|
275 | 270 | if not np.array_equal(data, subarr):
|
276 | 271 | raise TypeError("Unsafe NumPy casting, you must explicitly cast")
|
277 | 272 |
|
278 |
| - def _is_compatible_with_other(self, other) -> bool: |
279 |
| - return super()._is_compatible_with_other(other) or all( |
280 |
| - isinstance(obj, (ABCInt64Index, ABCFloat64Index, ABCRangeIndex)) |
281 |
| - for obj in [self, other] |
282 |
| - ) |
| 273 | + def _can_union_without_object_cast(self, other) -> bool: |
| 274 | + # See GH#26778, further casting may occur in NumericIndex._union |
| 275 | + return other.dtype == "f8" or other.dtype == self.dtype |
283 | 276 |
|
284 | 277 |
|
285 | 278 | Int64Index._add_numeric_methods()
|
@@ -324,10 +317,9 @@ def _assert_safe_casting(cls, data, subarr):
|
324 | 317 | if not np.array_equal(data, subarr):
|
325 | 318 | raise TypeError("Unsafe NumPy casting, you must explicitly cast")
|
326 | 319 |
|
327 |
| - def _is_compatible_with_other(self, other) -> bool: |
328 |
| - return super()._is_compatible_with_other(other) or all( |
329 |
| - isinstance(obj, (ABCUInt64Index, ABCFloat64Index)) for obj in [self, other] |
330 |
| - ) |
| 320 | + def _can_union_without_object_cast(self, other) -> bool: |
| 321 | + # See GH#26778, further casting may occur in NumericIndex._union |
| 322 | + return other.dtype == "f8" or other.dtype == self.dtype |
331 | 323 |
|
332 | 324 |
|
333 | 325 | UInt64Index._add_numeric_methods()
|
@@ -432,13 +424,9 @@ def isin(self, values, level=None):
|
432 | 424 | self._validate_index_level(level)
|
433 | 425 | return algorithms.isin(np.array(self), values)
|
434 | 426 |
|
435 |
| - def _is_compatible_with_other(self, other) -> bool: |
436 |
| - return super()._is_compatible_with_other(other) or all( |
437 |
| - isinstance( |
438 |
| - obj, (ABCInt64Index, ABCFloat64Index, ABCUInt64Index, ABCRangeIndex) |
439 |
| - ) |
440 |
| - for obj in [self, other] |
441 |
| - ) |
| 427 | + def _can_union_without_object_cast(self, other) -> bool: |
| 428 | + # See GH#26778, further casting may occur in NumericIndex._union |
| 429 | + return is_numeric_dtype(other.dtype) |
442 | 430 |
|
443 | 431 |
|
444 | 432 | Float64Index._add_numeric_methods()
|
|
0 commit comments