diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index b890deb62..1ae18d137 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -283,6 +283,8 @@ IndexIterScalar: TypeAlias = ( | float | Timestamp | Timedelta + | np.integer + | np.float_ ) Scalar: TypeAlias = IndexIterScalar | complex ScalarT = TypeVar("ScalarT", bound=Scalar) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 8ffbd5dff..c5f246b19 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1609,7 +1609,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): level: None = ..., numeric_only: _bool = ..., **kwargs, - ) -> float: ... + ) -> np.float64: ... def median( self, axis: AxisIndex | None = ..., diff --git a/tests/test_frame.py b/tests/test_frame.py index 99b323a67..e45f8b517 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -2042,12 +2042,12 @@ def test_groupby_apply() -> None: # GH 167 df = pd.DataFrame({"col1": [1, 2, 3], "col2": [4, 5, 6]}) - def sum_mean(x: pd.DataFrame) -> float: + def sum_mean(x: pd.DataFrame) -> np.float64: return x.sum().mean() check(assert_type(df.groupby("col1").apply(sum_mean), pd.Series), pd.Series) - lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean() + lfunc: Callable[[pd.DataFrame], np.float64] = lambda x: x.sum().mean() check( assert_type(df.groupby("col1").apply(lfunc), pd.Series), pd.Series, diff --git a/tests/test_resampler.py b/tests/test_resampler.py index c4287d1a9..a736317b2 100644 --- a/tests/test_resampler.py +++ b/tests/test_resampler.py @@ -158,7 +158,7 @@ def g(val: DataFrame) -> Series: check(assert_type(DF.resample("m").pipe(g), DataFrame), DataFrame) - def h(val: DataFrame) -> float: + def h(val: DataFrame) -> np.float64: return val.mean().mean() check(assert_type(DF.resample("m").pipe(h), Series), Series) @@ -248,10 +248,10 @@ def test_aggregate_series() -> None: DataFrame, ) - def f(val: Series) -> float: + def f(val: Series) -> np.float64: return val.mean() - check(assert_type(S.resample("m").aggregate(f), _AggRetType), Series) + check(assert_type(S.resample("m").aggregate(f), _AggRetType), pd.Series) def test_asfreq_series() -> None: diff --git a/tests/test_series.py b/tests/test_series.py index be89c210f..d741dd626 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -310,10 +310,10 @@ def test_types_rank() -> None: def test_types_mean() -> None: s = pd.Series([1, 2, 3, np.nan]) - f1: float = s.mean() + check(assert_type(s.mean(), np.float64), np.float64) s1: pd.Series = s.groupby(level=0).mean() - f2: float = s.mean(skipna=False) - f3: float = s.mean(numeric_only=False) + f2: np.float64 = s.mean(skipna=False) + f3: np.float64 = s.mean(numeric_only=False) def test_types_median() -> None: diff --git a/tests/test_windowing.py b/tests/test_windowing.py index bf0d88dbf..28fdf62ee 100644 --- a/tests/test_windowing.py +++ b/tests/test_windowing.py @@ -148,7 +148,7 @@ def test_rolling_basic_math_series() -> None: def test_rolling_apply_series() -> None: check(assert_type(S.rolling(10).apply(np.mean), Series), Series) - def _mean(df: Series) -> float: + def _mean(df: Series) -> np.float64: return df.mean() check(assert_type(S.rolling(10).apply(_mean), Series), Series) @@ -163,7 +163,7 @@ def test_rolling_aggregate_series() -> None: check(assert_type(S.rolling(10).aggregate(np.mean), Series), Series) check(assert_type(S.rolling(10).aggregate("mean"), Series), Series) - def _mean(s: Series) -> float: + def _mean(s: Series) -> np.float64: return s.mean() check(assert_type(S.rolling(10).aggregate(_mean), Series), Series) @@ -256,7 +256,7 @@ def test_expanding_basic_math_series() -> None: def test_expanding_apply_series() -> None: check(assert_type(S.expanding(10).apply(np.mean), Series), Series) - def _mean(df: Series) -> float: + def _mean(df: Series) -> np.float64: return df.mean() check(assert_type(S.expanding(10).apply(_mean), Series), Series)