From 4d2d186bceff3b71ebef957f74aba53e2d0fe125 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 4 Nov 2025 12:57:24 -0800 Subject: [PATCH 1/2] CLN: remove unnecessary return tuple elements --- pandas/core/arrays/numeric.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pandas/core/arrays/numeric.py b/pandas/core/arrays/numeric.py index 80fbbf99a5494..4afe78ccd922c 100644 --- a/pandas/core/arrays/numeric.py +++ b/pandas/core/arrays/numeric.py @@ -139,10 +139,9 @@ def _safe_cast(cls, values: np.ndarray, dtype: np.dtype, copy: bool) -> np.ndarr raise AbstractMethodError(cls) -def _coerce_to_data_and_mask( - values, dtype, copy: bool, dtype_cls: type[NumericDtype], default_dtype: np.dtype -): +def _coerce_to_data_and_mask(values, dtype, copy: bool, dtype_cls: type[NumericDtype]): checker = dtype_cls._checker + default_dtype = dtype_cls._default_np_dtype mask = None inferred_type = None @@ -163,17 +162,22 @@ def _coerce_to_data_and_mask( if copy: values = values.copy() mask = mask.copy() - return values, mask, dtype, inferred_type + return values, mask original = values if not copy: values = np.asarray(values) else: values = np.array(values, copy=copy) - inferred_type = None if values.dtype == object or is_string_dtype(values.dtype): - inferred_type = lib.infer_dtype(values, skipna=True) - if inferred_type == "boolean" and dtype is None: + if is_string_dtype(values.dtype): + inferred_type = "string" + if ( + dtype is None + and values.dtype == object + and lib.is_bool_array(values, skipna=True) + ): + # object dtype array of bools name = dtype_cls.__name__.strip("_") raise TypeError(f"{values.dtype} cannot be converted to {name}") @@ -252,7 +256,7 @@ def _coerce_to_data_and_mask( values = values.astype(dtype, copy=copy) else: values = dtype_cls._safe_cast(values, dtype, copy=False) - return values, mask, dtype, inferred_type + return values, mask class NumericArray(BaseMaskedArray): @@ -296,10 +300,7 @@ def _coerce_to_array( cls, value, *, dtype: DtypeObj, copy: bool = False ) -> tuple[np.ndarray, np.ndarray]: dtype_cls = cls._dtype_cls - default_dtype = dtype_cls._default_np_dtype - values, mask, _, _ = _coerce_to_data_and_mask( - value, dtype, copy, dtype_cls, default_dtype - ) + values, mask = _coerce_to_data_and_mask(value, dtype, copy, dtype_cls) return values, mask @classmethod From 983967f044cf2c2e42bbb4e56e0fb24a1970f75c Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 4 Nov 2025 15:14:15 -0800 Subject: [PATCH 2/2] revert condition change --- pandas/core/arrays/numeric.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pandas/core/arrays/numeric.py b/pandas/core/arrays/numeric.py index 4afe78ccd922c..2829d092ebba4 100644 --- a/pandas/core/arrays/numeric.py +++ b/pandas/core/arrays/numeric.py @@ -169,14 +169,10 @@ def _coerce_to_data_and_mask(values, dtype, copy: bool, dtype_cls: type[NumericD values = np.asarray(values) else: values = np.array(values, copy=copy) + inferred_type = None if values.dtype == object or is_string_dtype(values.dtype): - if is_string_dtype(values.dtype): - inferred_type = "string" - if ( - dtype is None - and values.dtype == object - and lib.is_bool_array(values, skipna=True) - ): + inferred_type = lib.infer_dtype(values, skipna=True) + if inferred_type == "boolean" and dtype is None: # object dtype array of bools name = dtype_cls.__name__.strip("_") raise TypeError(f"{values.dtype} cannot be converted to {name}")