Skip to content

Commit 386c421

Browse files
API: ignore empty range/object dtype in Index setop operations (string dtype compat)
1 parent f3045db commit 386c421

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pandas/core/indexes/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
import numpy as np
2121

22-
from pandas._config import get_option
22+
from pandas._config import (
23+
get_option,
24+
using_string_dtype,
25+
)
2326

2427
from pandas._libs import (
2528
NaT,
@@ -6233,8 +6236,16 @@ def _find_common_type_compat(self, target) -> DtypeObj:
62336236
Implementation of find_common_type that adjusts for Index-specific
62346237
special cases.
62356238
"""
6239+
# breakpoint()
62366240
target_dtype, _ = infer_dtype_from(target)
62376241

6242+
if using_string_dtype():
6243+
from pandas.core.indexes.range import RangeIndex
6244+
6245+
if len(self) == 0 or self.isna().all():
6246+
if isinstance(self, RangeIndex) or self.dtype == np.object_:
6247+
return target_dtype
6248+
62386249
# special case: if one dtype is uint64 and the other a signed int, return object
62396250
# See https://github.com/pandas-dev/pandas/issues/26778 for discussion
62406251
# Now it's:

0 commit comments

Comments
 (0)