Skip to content

BUG: Fix infer_dtype result for complex with pd.NA #61977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
6 changes: 4 additions & 2 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading