diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index a9841c4475822..b9f812e279d54 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -731,6 +731,7 @@ Timezones Numeric ^^^^^^^ +- Bug in :func:`api.types.infer_dtype` returning "mixed" for complex and ``pd.NA`` mix (:issue:`61976`) - Bug in :func:`api.types.infer_dtype` returning "mixed-integer-float" for float and ``pd.NA`` mix (:issue:`61621`) - Bug in :meth:`DataFrame.corr` where numerical precision errors resulted in correlations above ``1.0`` (:issue:`61120`) - Bug in :meth:`DataFrame.cov` raises a ``TypeError`` instead of returning potentially incorrect results or other errors (:issue:`53115`) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 6bb8e8ab46e59..83a1b09f00a11 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -1974,9 +1974,11 @@ cdef class ComplexValidator(Validator): return cnp.PyDataType_ISCOMPLEX(self.dtype) -cdef bint is_complex_array(ndarray values): +cdef bint is_complex_array(ndarray values, bint skipna=True): cdef: - ComplexValidator validator = ComplexValidator(values.size, values.dtype) + ComplexValidator validator = ComplexValidator(values.size, + values.dtype, + skipna=skipna) return validator.validate(values) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 6e08ebda88420..b83a09e7f2e18 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1405,6 +1405,10 @@ def test_infer_dtype_numeric_with_na(self, na_value): ser = Series([1.0, 2.0, na_value], dtype=object) assert lib.infer_dtype(ser, skipna=True) == "floating" + # GH#61976 + ser = Series([1 + 1j, na_value], dtype=object) + assert lib.infer_dtype(ser, skipna=True) == "complex" + def test_infer_dtype_all_nan_nat_like(self): arr = np.array([np.nan, np.nan]) assert lib.infer_dtype(arr, skipna=True) == "floating"