Skip to content

Commit

Permalink
Use is_float_dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolheater committed Oct 23, 2024
1 parent cc63891 commit edc977e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pandas/core/array_algos/masked_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 (
Expand Down
13 changes: 5 additions & 8 deletions pandas/tests/series/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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))

0 comments on commit edc977e

Please sign in to comment.