From 581665ac03f9b526cdcbee176b0273334eef6598 Mon Sep 17 00:00:00 2001 From: Kyungtae Kim Date: Wed, 23 Oct 2024 23:27:46 +0900 Subject: [PATCH] Use is_float_dtype --- pandas/core/array_algos/masked_reductions.py | 4 +++- pandas/tests/series/test_reductions.py | 13 +++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pandas/core/array_algos/masked_reductions.py b/pandas/core/array_algos/masked_reductions.py index 83b12cf4723c9a..6d095699d99951 100644 --- a/pandas/core/array_algos/masked_reductions.py +++ b/pandas/core/array_algos/masked_reductions.py @@ -12,6 +12,8 @@ from pandas._libs import missing as libmissing +from pandas.core.dtypes.common import is_float_dtype + from pandas.core.missing import isna from pandas.core.nanops import check_below_min_count @@ -58,7 +60,7 @@ def _reductions( else: return func(values, axis=axis, **kwargs) else: - if values.dtype == np.float64: + if is_float_dtype(values): mask |= isna(values) if check_below_min_count(values.shape, mask, min_count) and ( diff --git a/pandas/tests/series/test_reductions.py b/pandas/tests/series/test_reductions.py index a038b6d5bbc5bf..27bfb854abc037 100644 --- a/pandas/tests/series/test_reductions.py +++ b/pandas/tests/series/test_reductions.py @@ -6,10 +6,7 @@ from pandas.compat import HAS_PYARROW import pandas as pd -from pandas import ( - Series, - notna, -) +from pandas import Series import pandas._testing as tm @@ -230,7 +227,7 @@ def test_median_with_convertible_string_raises(): 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)) + series1 = Series({"a": 0.0, "b": 1, "c": 1}, dtype="Float64") + series2 = Series({"a": 0.0, "b": 2, "c": 2}, dtype="Float64") + result = series1 / series2 + assert pd.notna(result.mean(skipna=True))