Skip to content

Commit 0b4497d

Browse files
Override RangeIndex._find_common_type_compat
1 parent e0b7c0a commit 0b4497d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pandas/core/indexes/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -6228,7 +6228,6 @@ def _maybe_promote(self, other: Index) -> tuple[Index, Index]:
62286228

62296229
return self, other
62306230

6231-
@final
62326231
def _find_common_type_compat(self, target) -> DtypeObj:
62336232
"""
62346233
Implementation of find_common_type that adjusts for Index-specific

pandas/core/indexes/range.py

+24
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
doc,
2828
)
2929

30+
from pandas.core.dtypes.cast import (
31+
_dtype_obj,
32+
find_common_type,
33+
infer_dtype_from,
34+
)
3035
from pandas.core.dtypes.common import (
3136
ensure_platform_int,
3237
ensure_python_int,
@@ -51,6 +56,7 @@
5156
from pandas._typing import (
5257
Axis,
5358
Dtype,
59+
DtypeObj,
5460
NaPosition,
5561
Self,
5662
npt,
@@ -1084,3 +1090,21 @@ def take(
10841090

10851091
# _constructor so RangeIndex-> Index with an int64 dtype
10861092
return self._constructor._simple_new(taken, name=self.name)
1093+
1094+
def _find_common_type_compat(self, target) -> DtypeObj:
1095+
target_dtype, _ = infer_dtype_from(target)
1096+
1097+
# special case: if one dtype is uint64 and the other a signed int, return object
1098+
# See https://github.com/pandas-dev/pandas/issues/26778 for discussion
1099+
# Now it's:
1100+
# * float | [u]int -> float
1101+
# * uint64 | signed int -> object
1102+
# We may change union(float | [u]int) to go to object.
1103+
if self.dtype == "uint64" or target_dtype == "uint64":
1104+
if is_signed_integer_dtype(self.dtype) or is_signed_integer_dtype(
1105+
target_dtype
1106+
):
1107+
return _dtype_obj
1108+
1109+
dtype = find_common_type([self.dtype, target_dtype])
1110+
return dtype

0 commit comments

Comments
 (0)