Skip to content

Commit

Permalink
BUG: fix pandas-dev#59965 skipna=True operations don't skip NaN in Fl…
Browse files Browse the repository at this point in the history
…oatingArrays

    - 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
  • Loading branch information
cooolheater committed Oct 7, 2024
1 parent 5829e3e commit 218e5cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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))

0 comments on commit 218e5cd

Please sign in to comment.