From cc63891b8641e57b3f41a026297896cf93222a3f Mon Sep 17 00:00:00 2001 From: Kyungtae Kim Date: Mon, 14 Oct 2024 20:44:45 +0900 Subject: [PATCH] Apply mask for only the type that can become null after calculation --- pandas/core/array_algos/masked_reductions.py | 3 ++- pandas/tests/series/test_reductions.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pandas/core/array_algos/masked_reductions.py b/pandas/core/array_algos/masked_reductions.py index 4a5a8f0c4e61d..83b12cf4723c9 100644 --- a/pandas/core/array_algos/masked_reductions.py +++ b/pandas/core/array_algos/masked_reductions.py @@ -58,7 +58,8 @@ def _reductions( else: return func(values, axis=axis, **kwargs) else: - mask |= isna(values) + 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 diff --git a/pandas/tests/series/test_reductions.py b/pandas/tests/series/test_reductions.py index 15ed3097db8ac..a038b6d5bbc5b 100644 --- a/pandas/tests/series/test_reductions.py +++ b/pandas/tests/series/test_reductions.py @@ -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 @@ -230,4 +233,4 @@ def test_mean_with_skipna(): 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)) + assert notna(result.mean(skipna=True))