Skip to content

Commit 74845ea

Browse files
committed
style: fix flake8 issues in np_can_hold_element refactor
1 parent 1b16585 commit 74845ea

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

pandas/core/dtypes/cast.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,8 @@ def _handle_integer_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
17871787
17881788
Raises
17891789
------
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.
17911792
"""
17921793
if isinstance(element, range):
17931794
if _dtype_can_hold_range(element, dtype):
@@ -1822,7 +1823,7 @@ def _handle_integer_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
18221823
raise LossySetitemError
18231824

18241825
elif isinstance(element, ABCExtensionArray) and isinstance(
1825-
element.dtype, CategoricalDtype
1826+
element.dtype, CategoricalDtype
18261827
):
18271828
# GH#52927 setting Categorical value into non-EA frame
18281829
# TODO: general-case for EAs?
@@ -1842,9 +1843,9 @@ def _handle_integer_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
18421843
raise LossySetitemError
18431844

18441845
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"
18481849
):
18491850
# see test_where_uint64
18501851
casted = element.astype(dtype)
@@ -1864,6 +1865,7 @@ def _handle_integer_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
18641865
return element
18651866
return element
18661867

1868+
18671869
def _handle_float_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
18681870
"""
18691871
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:
18841886
18851887
Raises
18861888
------
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.
18881891
"""
18891892
if lib.is_integer(element) or lib.is_float(element):
18901893
casted = dtype.type(element)
@@ -1916,6 +1919,7 @@ def _handle_float_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
19161919

19171920
return element
19181921

1922+
19191923
def _handle_complex_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
19201924
"""
19211925
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:
19361940
19371941
Raises
19381942
------
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.
19401945
"""
19411946
if lib.is_integer(element) or lib.is_complex(element) or lib.is_float(element):
19421947
if np.isnan(element):
@@ -1956,6 +1961,7 @@ def _handle_complex_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
19561961
return element
19571962
raise LossySetitemError
19581963

1964+
19591965
def _handle_boolean_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
19601966
"""
19611967
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:
19761982
19771983
Raises
19781984
------
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.
19801987
"""
19811988
if lib.is_bool(element):
19821989
return element
@@ -1991,6 +1998,7 @@ def _handle_boolean_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
19911998
return element
19921999
raise LossySetitemError
19932000

2001+
19942002
def _handle_string_dtype(dtype: np.dtype, element: Any, tipo: np.dtype) -> Any:
19952003
"""
19962004
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:
20112019
20122020
Raises
20132021
------
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.
20152024
"""
20162025
# TODO: test tests.frame.methods.test_replace tests get here,
20172026
# 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:
20232032
return element
20242033
raise LossySetitemError
20252034

2035+
20262036
def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
20272037
"""
20282038
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:
20622072
raise NotImplementedError(dtype)
20632073

20642074

2065-
20662075
def _dtype_can_hold_range(rng: range, dtype: np.dtype) -> bool:
20672076
"""
20682077
_maybe_infer_dtype_type infers to int64 (and float64 for very large endpoints),

0 commit comments

Comments
 (0)