|
8 | 8 | import numpy as np
|
9 | 9 |
|
10 | 10 | from pandas._libs import NaT, Timestamp, algos as libalgos, lib, tslib, writers
|
11 |
| -from pandas._libs.index import convert_scalar |
12 | 11 | import pandas._libs.internals as libinternals
|
13 | 12 | from pandas._libs.tslibs import Timedelta, conversion
|
14 | 13 | from pandas._libs.tslibs.timezones import tz_compare
|
15 | 14 | from pandas.util._validators import validate_bool_kwarg
|
16 | 15 |
|
17 | 16 | from pandas.core.dtypes.cast import (
|
18 | 17 | astype_nansafe,
|
| 18 | + convert_scalar_for_putitemlike, |
19 | 19 | find_common_type,
|
20 | 20 | infer_dtype_from,
|
21 | 21 | infer_dtype_from_scalar,
|
@@ -762,7 +762,7 @@ def replace(
|
762 | 762 | # The only non-DatetimeLike class that also has a non-trivial
|
763 | 763 | # try_coerce_args is ObjectBlock, but that overrides replace,
|
764 | 764 | # so does not get here.
|
765 |
| - to_replace = convert_scalar(values, to_replace) |
| 765 | + to_replace = convert_scalar_for_putitemlike(to_replace, values.dtype) |
766 | 766 |
|
767 | 767 | mask = missing.mask_missing(values, to_replace)
|
768 | 768 | if filter is not None:
|
@@ -841,7 +841,7 @@ def setitem(self, indexer, value):
|
841 | 841 | # We only get here for non-Extension Blocks, so _try_coerce_args
|
842 | 842 | # is only relevant for DatetimeBlock and TimedeltaBlock
|
843 | 843 | if lib.is_scalar(value):
|
844 |
| - value = convert_scalar(values, value) |
| 844 | + value = convert_scalar_for_putitemlike(value, values.dtype) |
845 | 845 |
|
846 | 846 | else:
|
847 | 847 | # current dtype cannot store value, coerce to common dtype
|
@@ -957,7 +957,7 @@ def putmask(self, mask, new, align=True, inplace=False, axis=0, transpose=False)
|
957 | 957 | # We only get here for non-Extension Blocks, so _try_coerce_args
|
958 | 958 | # is only relevant for DatetimeBlock and TimedeltaBlock
|
959 | 959 | if lib.is_scalar(new):
|
960 |
| - new = convert_scalar(new_values, new) |
| 960 | + new = convert_scalar_for_putitemlike(new, new_values.dtype) |
961 | 961 |
|
962 | 962 | if transpose:
|
963 | 963 | new_values = new_values.T
|
@@ -1200,7 +1200,7 @@ def _interpolate_with_fill(
|
1200 | 1200 | values = self.values if inplace else self.values.copy()
|
1201 | 1201 |
|
1202 | 1202 | # We only get here for non-ExtensionBlock
|
1203 |
| - fill_value = convert_scalar(self.values, fill_value) |
| 1203 | + fill_value = convert_scalar_for_putitemlike(fill_value, self.values.dtype) |
1204 | 1204 |
|
1205 | 1205 | values = missing.interpolate_2d(
|
1206 | 1206 | values,
|
@@ -1405,7 +1405,7 @@ def where_func(cond, values, other):
|
1405 | 1405 | raise TypeError
|
1406 | 1406 | if lib.is_scalar(other) and isinstance(values, np.ndarray):
|
1407 | 1407 | # convert datetime to datetime64, timedelta to timedelta64
|
1408 |
| - other = convert_scalar(values, other) |
| 1408 | + other = convert_scalar_for_putitemlike(other, values.dtype) |
1409 | 1409 |
|
1410 | 1410 | # By the time we get here, we should have all Series/Index
|
1411 | 1411 | # args extracted to ndarray
|
|
0 commit comments