Skip to content

Commit c750fb4

Browse files
authored
REF: maybe_promote -> find_common_type (#39437)
1 parent 71f40a6 commit c750fb4

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pandas/core/indexes/base.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242
from pandas.core.dtypes.cast import (
4343
find_common_type,
44+
infer_dtype_from,
4445
maybe_cast_to_integer_array,
45-
maybe_promote,
4646
validate_numeric_casting,
4747
)
4848
from pandas.core.dtypes.common import (
@@ -87,7 +87,7 @@
8787
ABCTimedeltaIndex,
8888
)
8989
from pandas.core.dtypes.inference import is_dict_like
90-
from pandas.core.dtypes.missing import array_equivalent, isna
90+
from pandas.core.dtypes.missing import array_equivalent, is_valid_nat_for_dtype, isna
9191

9292
from pandas.core import missing, ops
9393
from pandas.core.accessor import CachedAccessor
@@ -5735,16 +5735,14 @@ def insert(self, loc: int, item):
57355735
# Note: this method is overridden by all ExtensionIndex subclasses,
57365736
# so self is never backed by an EA.
57375737
item = lib.item_from_zerodim(item)
5738+
if is_valid_nat_for_dtype(item, self.dtype) and self.dtype != object:
5739+
item = self._na_value
57385740

57395741
try:
57405742
item = self._validate_fill_value(item)
57415743
except TypeError:
5742-
if is_scalar(item):
5743-
dtype, item = maybe_promote(self.dtype, item)
5744-
else:
5745-
# maybe_promote would raise ValueError
5746-
dtype = np.dtype(object)
5747-
5744+
inferred, _ = infer_dtype_from(item)
5745+
dtype = find_common_type([self.dtype, inferred])
57485746
return self.astype(dtype).insert(loc, item)
57495747

57505748
arr = np.asarray(self)

0 commit comments

Comments
 (0)