Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 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,9 @@ def _reductions(
else:
return func(values, axis=axis, **kwargs)
else:
if values.dtype == np.float64:
mask |= isna(values)

if check_below_min_count(values.shape, mask, min_count) and (
axis is None or values.ndim == 1
):
Expand Down
13 changes: 12 additions & 1 deletion pandas/tests/series/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from pandas.compat import HAS_PYARROW

import pandas as pd
from pandas import Series
from pandas import (
Series,
notna,
)
import pandas._testing as tm


Expand Down Expand Up @@ -223,3 +226,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 notna(result.mean(skipna=True))