@@ -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-
19111852def 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