Skip to content

Commit 8a0dfc6

Browse files
jbrockmendelyehoshuadimarsky
authored andcommitted
REF: remove no-longer-needed _validate_numeric_casting (pandas-dev#46131)
1 parent 44cd15b commit 8a0dfc6

File tree

2 files changed

+1
-66
lines changed

2 files changed

+1
-66
lines changed

pandas/core/array_algos/putmask.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
)
1515
from pandas.compat import np_version_under1p20
1616

17-
from pandas.core.dtypes.cast import (
18-
convert_scalar_for_putitemlike,
19-
infer_dtype_from,
20-
)
17+
from pandas.core.dtypes.cast import infer_dtype_from
2118
from pandas.core.dtypes.common import is_list_like
2219

2320
from pandas.core.arrays import ExtensionArray
@@ -36,9 +33,6 @@ def putmask_inplace(values: ArrayLike, mask: npt.NDArray[np.bool_], value: Any)
3633
value : Any
3734
"""
3835

39-
if lib.is_scalar(value) and isinstance(values, np.ndarray):
40-
value = convert_scalar_for_putitemlike(value, values.dtype)
41-
4236
if (
4337
not isinstance(values, np.ndarray)
4438
or (values.dtype == object and not lib.is_scalar(value))

pandas/core/dtypes/cast.py

-59
Original file line numberDiff line numberDiff line change
@@ -1849,65 +1849,6 @@ def maybe_cast_to_integer_array(
18491849
raise ValueError(f"values cannot be losslessly cast to {dtype}")
18501850

18511851

1852-
def convert_scalar_for_putitemlike(scalar: Scalar, dtype: np.dtype) -> Scalar:
1853-
"""
1854-
Convert datetimelike scalar if we are setting into a datetime64
1855-
or timedelta64 ndarray.
1856-
1857-
Parameters
1858-
----------
1859-
scalar : scalar
1860-
dtype : np.dtype
1861-
1862-
Returns
1863-
-------
1864-
scalar
1865-
"""
1866-
if dtype.kind in ["m", "M"]:
1867-
scalar = maybe_box_datetimelike(scalar, dtype)
1868-
return _maybe_unbox_datetimelike(scalar, dtype)
1869-
else:
1870-
_validate_numeric_casting(dtype, scalar)
1871-
return scalar
1872-
1873-
1874-
def _validate_numeric_casting(dtype: np.dtype, value: Scalar) -> None:
1875-
"""
1876-
Check that we can losslessly insert the given value into an array
1877-
with the given dtype.
1878-
1879-
Parameters
1880-
----------
1881-
dtype : np.dtype
1882-
value : scalar
1883-
1884-
Raises
1885-
------
1886-
ValueError
1887-
"""
1888-
# error: Argument 1 to "__call__" of "ufunc" has incompatible type
1889-
# "Union[Union[str, int, float, bool], Union[Any, Timestamp, Timedelta, Any]]";
1890-
# expected "Union[Union[int, float, complex, str, bytes, generic],
1891-
# Sequence[Union[int, float, complex, str, bytes, generic]],
1892-
# Sequence[Sequence[Any]], _SupportsArray]"
1893-
if (
1894-
issubclass(dtype.type, (np.integer, np.bool_))
1895-
and is_float(value)
1896-
and np.isnan(value) # type: ignore[arg-type]
1897-
):
1898-
raise ValueError("Cannot assign nan to integer series")
1899-
1900-
elif dtype.kind in ["i", "u", "f", "c"]:
1901-
if is_bool(value) or isinstance(value, np.timedelta64):
1902-
# numpy will cast td64 to integer if we're not careful
1903-
raise ValueError(
1904-
f"Cannot assign {type(value).__name__} to float/integer series"
1905-
)
1906-
elif dtype.kind == "b":
1907-
if is_scalar(value) and not is_bool(value):
1908-
raise ValueError(f"Cannot assign {type(value).__name__} to bool series")
1909-
1910-
19111852
def can_hold_element(arr: ArrayLike, element: Any) -> bool:
19121853
"""
19131854
Can we do an inplace setitem with this element in an array with this dtype?

0 commit comments

Comments
 (0)