Skip to content

Commit 7802c69

Browse files
authored
Follow up PR for changes requested in #445 (#451)
* Follow up PR for changes requested in #445 * updated the test_frame.py by changing the assert-type and adding the second check type
1 parent 68780c7 commit 7802c69

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

pandas-stubs/core/groupby/generic.pyi

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,24 @@ class SeriesGroupBy(GroupBy, Generic[S1]):
6565
def filter(self, func, dropna: bool = ..., *args, **kwargs): ...
6666
def nunique(self, dropna: bool = ...) -> Series: ...
6767
def describe(self, **kwargs) -> DataFrame: ...
68+
@overload
6869
def value_counts(
6970
self,
70-
normalize: Literal[False, True] = ...,
71+
normalize: Literal[False] = ...,
7172
sort: bool = ...,
7273
ascending: bool = ...,
7374
bins=...,
7475
dropna: bool = ...,
75-
) -> Series: ...
76+
) -> Series[int]: ...
77+
@overload
78+
def value_counts(
79+
self,
80+
normalize: Literal[True],
81+
sort: bool = ...,
82+
ascending: bool = ...,
83+
bins=...,
84+
dropna: bool = ...,
85+
) -> Series[float]: ...
7686
def count(self) -> Series[int]: ...
7787
def pct_change(
7888
self,

tests/test_frame.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,8 +2040,10 @@ def test_series_groupby_and_value_counts() -> None:
20402040
"Max Speed": [380, 370, 24, 26],
20412041
}
20422042
)
2043-
c: pd.Series = df.groupby("Animal")["Max Speed"].value_counts()
2044-
check(assert_type(c, pd.Series), pd.Series)
2043+
c1 = df.groupby("Animal")["Max Speed"].value_counts()
2044+
c2 = df.groupby("Animal")["Max Speed"].value_counts(normalize=True)
2045+
check(assert_type(c1, "pd.Series[int]"), pd.Series, int)
2046+
check(assert_type(c2, "pd.Series[float]"), pd.Series, float)
20452047

20462048

20472049
def test_axes_as_tuple() -> None:

0 commit comments

Comments
 (0)