Skip to content

Commit 2323b10

Browse files
authored
type bins in seriesgroupby.value_counts (#1130)
1 parent 25fe8aa commit 2323b10

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

pandas-stubs/core/groupby/generic.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class SeriesGroupBy(GroupBy[Series[S1]], Generic[S1, ByT]):
101101
normalize: Literal[False] = ...,
102102
sort: bool = ...,
103103
ascending: bool = ...,
104-
bins=...,
104+
bins: int | Sequence[int] | None = ...,
105105
dropna: bool = ...,
106106
) -> Series[int]: ...
107107
@overload
@@ -110,7 +110,7 @@ class SeriesGroupBy(GroupBy[Series[S1]], Generic[S1, ByT]):
110110
normalize: Literal[True],
111111
sort: bool = ...,
112112
ascending: bool = ...,
113-
bins=...,
113+
bins: int | Sequence[int] | None = ...,
114114
dropna: bool = ...,
115115
) -> Series[float]: ...
116116
def fillna(

tests/test_groupby.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,3 +1062,30 @@ def test_groupby_getitem() -> None:
10621062
df = DataFrame(np.random.random((3, 4)), columns=["a", "b", "c", "d"])
10631063
check(assert_type(df.groupby("a")["b"].sum(), Series), Series, float)
10641064
check(assert_type(df.groupby("a")[["b", "c"]].sum(), DataFrame), DataFrame)
1065+
1066+
1067+
def test_series_value_counts() -> None:
1068+
df = DataFrame({"a": [1, 1, 2], "b": [4, 5, 6]})
1069+
check(
1070+
assert_type(df.groupby("a")["b"].value_counts(), "Series[int]"),
1071+
Series,
1072+
np.int64,
1073+
)
1074+
check(
1075+
assert_type(df.groupby("a")["b"].value_counts(bins=[3, 5, 7]), "Series[int]"),
1076+
Series,
1077+
np.int64,
1078+
)
1079+
check(
1080+
assert_type(df.groupby("a")["b"].value_counts(normalize=True), "Series[float]"),
1081+
Series,
1082+
np.float64,
1083+
)
1084+
check(
1085+
assert_type(
1086+
df.groupby("a")["b"].value_counts(bins=(3, 5, 7), normalize=True),
1087+
"Series[float]",
1088+
),
1089+
Series,
1090+
np.float64,
1091+
)

0 commit comments

Comments
 (0)