Skip to content

Commit b2fbf09

Browse files
yuanx749XY
andauthored
BUG: Fix infer_dtype result for complex with pd.NA (#61977)
Co-authored-by: XY <yuanx749@outlook.com>
1 parent 94d9d2e commit b2fbf09

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ Timezones
731731

732732
Numeric
733733
^^^^^^^
734+
- Bug in :func:`api.types.infer_dtype` returning "mixed" for complex and ``pd.NA`` mix (:issue:`61976`)
734735
- Bug in :func:`api.types.infer_dtype` returning "mixed-integer-float" for float and ``pd.NA`` mix (:issue:`61621`)
735736
- Bug in :meth:`DataFrame.corr` where numerical precision errors resulted in correlations above ``1.0`` (:issue:`61120`)
736737
- Bug in :meth:`DataFrame.cov` raises a ``TypeError`` instead of returning potentially incorrect results or other errors (:issue:`53115`)

pandas/_libs/lib.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,9 +1974,11 @@ cdef class ComplexValidator(Validator):
19741974
return cnp.PyDataType_ISCOMPLEX(self.dtype)
19751975

19761976

1977-
cdef bint is_complex_array(ndarray values):
1977+
cdef bint is_complex_array(ndarray values, bint skipna=True):
19781978
cdef:
1979-
ComplexValidator validator = ComplexValidator(values.size, values.dtype)
1979+
ComplexValidator validator = ComplexValidator(values.size,
1980+
values.dtype,
1981+
skipna=skipna)
19801982
return validator.validate(values)
19811983

19821984

pandas/tests/dtypes/test_inference.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,10 @@ def test_infer_dtype_numeric_with_na(self, na_value):
14051405
ser = Series([1.0, 2.0, na_value], dtype=object)
14061406
assert lib.infer_dtype(ser, skipna=True) == "floating"
14071407

1408+
# GH#61976
1409+
ser = Series([1 + 1j, na_value], dtype=object)
1410+
assert lib.infer_dtype(ser, skipna=True) == "complex"
1411+
14081412
def test_infer_dtype_all_nan_nat_like(self):
14091413
arr = np.array([np.nan, np.nan])
14101414
assert lib.infer_dtype(arr, skipna=True) == "floating"

0 commit comments

Comments
 (0)