Skip to content

Commit 218e5cd

Browse files
committed
BUG: fix #59965 skipna=True operations don't skip NaN in FloatingArrays
- Issue: The skipna was not properly handled for BaseMaskedArray - Fix: Added mask for NA values - Test: Added test to series/test_reductions since the test uses
1 parent 5829e3e commit 218e5cd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pandas/core/array_algos/masked_reductions.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from pandas._libs import missing as libmissing
1414

15+
from pandas.core.missing import isna
1516
from pandas.core.nanops import check_below_min_count
1617

1718
if TYPE_CHECKING:
@@ -57,6 +58,8 @@ def _reductions(
5758
else:
5859
return func(values, axis=axis, **kwargs)
5960
else:
61+
mask |= isna(values)
62+
6063
if check_below_min_count(values.shape, mask, min_count) and (
6164
axis is None or values.ndim == 1
6265
):

pandas/tests/series/test_reductions.py

+8
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,11 @@ def test_median_with_convertible_string_raises():
223223
df = ser.to_frame()
224224
with pytest.raises(TypeError, match=msg):
225225
df.median()
226+
227+
228+
def test_mean_with_skipna():
229+
# GH#59965 skipna=True operations don't skip NaN in FloatingArrays
230+
series1 = Series({"a": 0.0, "b": 1, "c": 1})
231+
series2 = Series({"a": 0.0, "b": 2, "c": 2})
232+
result = series1.convert_dtypes() / series2.convert_dtypes()
233+
assert pd.notna(result.mean(skipna=True))

0 commit comments

Comments
 (0)