@@ -1787,7 +1787,8 @@ def _handle_integer_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1787
1787
1788
1788
Raises
1789
1789
------
1790
- LossySetitemError: If the element cannot be losslessly stored in the given integer dtype.
1790
+ LossySetitemError: If the element cannot be
1791
+ losslessly stored in the given integer dtype.
1791
1792
"""
1792
1793
if isinstance (element , range ):
1793
1794
if _dtype_can_hold_range (element , dtype ):
@@ -1822,7 +1823,7 @@ def _handle_integer_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1822
1823
raise LossySetitemError
1823
1824
1824
1825
elif isinstance (element , ABCExtensionArray ) and isinstance (
1825
- element .dtype , CategoricalDtype
1826
+ element .dtype , CategoricalDtype
1826
1827
):
1827
1828
# GH#52927 setting Categorical value into non-EA frame
1828
1829
# TODO: general-case for EAs?
@@ -1842,9 +1843,9 @@ def _handle_integer_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1842
1843
raise LossySetitemError
1843
1844
1844
1845
if (
1845
- dtype .kind == "u"
1846
- and isinstance (element , np .ndarray )
1847
- and element .dtype .kind == "i"
1846
+ dtype .kind == "u"
1847
+ and isinstance (element , np .ndarray )
1848
+ and element .dtype .kind == "i"
1848
1849
):
1849
1850
# see test_where_uint64
1850
1851
casted = element .astype (dtype )
@@ -1864,6 +1865,7 @@ def _handle_integer_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1864
1865
return element
1865
1866
return element
1866
1867
1868
+
1867
1869
def _handle_float_dtype (dtype : np .dtype , element : Any , tipo : np .dtype ) -> Any :
1868
1870
"""
1869
1871
Handles casting or validation of an element for floating-point dtypes.
@@ -1884,7 +1886,8 @@ def _handle_float_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1884
1886
1885
1887
Raises
1886
1888
------
1887
- LossySetitemError: If the element cannot be losslessly stored in the given float dtype.
1889
+ LossySetitemError: If the element cannot be losslessly
1890
+ stored in the given float dtype.
1888
1891
"""
1889
1892
if lib .is_integer (element ) or lib .is_float (element ):
1890
1893
casted = dtype .type (element )
@@ -1916,6 +1919,7 @@ def _handle_float_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1916
1919
1917
1920
return element
1918
1921
1922
+
1919
1923
def _handle_complex_dtype (dtype : np .dtype , element : Any , tipo : np .dtype ) -> Any :
1920
1924
"""
1921
1925
Handles casting or validation of an element for complex dtypes.
@@ -1936,7 +1940,8 @@ def _handle_complex_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1936
1940
1937
1941
Raises
1938
1942
------
1939
- LossySetitemError: If the element cannot be losslessly stored in the given complex dtype.
1943
+ LossySetitemError: If the element cannot be
1944
+ losslessly stored in the given complex dtype.
1940
1945
"""
1941
1946
if lib .is_integer (element ) or lib .is_complex (element ) or lib .is_float (element ):
1942
1947
if np .isnan (element ):
@@ -1956,6 +1961,7 @@ def _handle_complex_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1956
1961
return element
1957
1962
raise LossySetitemError
1958
1963
1964
+
1959
1965
def _handle_boolean_dtype (dtype : np .dtype , element : Any , tipo : np .dtype ) -> Any :
1960
1966
"""
1961
1967
Handles casting or validation of an element for boolean dtypes.
@@ -1976,7 +1982,8 @@ def _handle_boolean_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1976
1982
1977
1983
Raises
1978
1984
------
1979
- LossySetitemError: If the element cannot be losslessly stored in the given boolean dtype.
1985
+ LossySetitemError: If the element cannot be
1986
+ losslessly stored in the given boolean dtype.
1980
1987
"""
1981
1988
if lib .is_bool (element ):
1982
1989
return element
@@ -1991,6 +1998,7 @@ def _handle_boolean_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
1991
1998
return element
1992
1999
raise LossySetitemError
1993
2000
2001
+
1994
2002
def _handle_string_dtype (dtype : np .dtype , element : Any , tipo : np .dtype ) -> Any :
1995
2003
"""
1996
2004
Handles casting or validation of an element for string (byte) dtypes.
@@ -2011,7 +2019,8 @@ def _handle_string_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
2011
2019
2012
2020
Raises
2013
2021
------
2014
- LossySetitemError: If the element cannot be losslessly stored in the given string dtype.
2022
+ LossySetitemError: If the element cannot be
2023
+ losslessly stored in the given string dtype.
2015
2024
"""
2016
2025
# TODO: test tests.frame.methods.test_replace tests get here,
2017
2026
# need more targeted tests. xref phofl has a PR about this
@@ -2023,6 +2032,7 @@ def _handle_string_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
2023
2032
return element
2024
2033
raise LossySetitemError
2025
2034
2035
+
2026
2036
def np_can_hold_element (dtype : np .dtype , element : Any ) -> Any :
2027
2037
"""
2028
2038
Raise if we cannot losslessly set this element into an ndarray with this dtype.
@@ -2062,7 +2072,6 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
2062
2072
raise NotImplementedError (dtype )
2063
2073
2064
2074
2065
-
2066
2075
def _dtype_can_hold_range (rng : range , dtype : np .dtype ) -> bool :
2067
2076
"""
2068
2077
_maybe_infer_dtype_type infers to int64 (and float64 for very large endpoints),
0 commit comments