Skip to content

BUG: fix #59965 skipna=True operations don't skip NaN in FloatingArrays #59997

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

Closed
wants to merge 11 commits into from
3 changes: 3 additions & 0 deletions pandas/core/array_algos/masked_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from pandas._libs import missing as libmissing

from pandas.core.missing import isna
from pandas.core.nanops import check_below_min_count

if TYPE_CHECKING:
Expand Down Expand Up @@ -57,6 +58,8 @@ def _reductions(
else:
return func(values, axis=axis, **kwargs)
else:
mask |= isna(values)

if check_below_min_count(values.shape, mask, min_count) and (
axis is None or values.ndim == 1
):
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/series/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,11 @@ def test_median_with_convertible_string_raises():
df = ser.to_frame()
with pytest.raises(TypeError, match=msg):
df.median()


def test_mean_with_skipna():
# GH#59965 skipna=True operations don't skip NaN in FloatingArrays
series1 = Series({"a": 0.0, "b": 1, "c": 1})
series2 = Series({"a": 0.0, "b": 2, "c": 2})
result = series1.convert_dtypes() / series2.convert_dtypes()
assert pd.notna(result.mean(skipna=True))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you assert the value here (it is a slightly stronger test). Can use np.isclose.