diff --git a/pandas-stubs/core/groupby/generic.pyi b/pandas-stubs/core/groupby/generic.pyi index 9f5a2d177..f909692d9 100644 --- a/pandas-stubs/core/groupby/generic.pyi +++ b/pandas-stubs/core/groupby/generic.pyi @@ -65,14 +65,24 @@ class SeriesGroupBy(GroupBy, Generic[S1]): def filter(self, func, dropna: bool = ..., *args, **kwargs): ... def nunique(self, dropna: bool = ...) -> Series: ... def describe(self, **kwargs) -> DataFrame: ... + @overload def value_counts( self, - normalize: Literal[False, True] = ..., + normalize: Literal[False] = ..., sort: bool = ..., ascending: bool = ..., bins=..., dropna: bool = ..., - ) -> Series: ... + ) -> Series[int]: ... + @overload + def value_counts( + self, + normalize: Literal[True], + sort: bool = ..., + ascending: bool = ..., + bins=..., + dropna: bool = ..., + ) -> Series[float]: ... def count(self) -> Series[int]: ... def pct_change( self, diff --git a/tests/test_frame.py b/tests/test_frame.py index a6a5bc015..1ea652605 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -2040,8 +2040,10 @@ def test_series_groupby_and_value_counts() -> None: "Max Speed": [380, 370, 24, 26], } ) - c: pd.Series = df.groupby("Animal")["Max Speed"].value_counts() - check(assert_type(c, pd.Series), pd.Series) + c1 = df.groupby("Animal")["Max Speed"].value_counts() + c2 = df.groupby("Animal")["Max Speed"].value_counts(normalize=True) + check(assert_type(c1, "pd.Series[int]"), pd.Series, int) + check(assert_type(c2, "pd.Series[float]"), pd.Series, float) def test_setitem_none() -> None: