Skip to content

Commit 966aebf

Browse files
GH1339 Allow DataFrame.groupby.aggregate with unpacked dictionary (#1340)
1 parent e799ec1 commit 966aebf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pandas-stubs/core/groupby/generic.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
264264
engine_kwargs: WindowingEngineKwargs = ...,
265265
**kwargs,
266266
) -> DataFrame: ...
267+
@overload
268+
def aggregate(
269+
self,
270+
func: AggFuncTypeFrame | None = None,
271+
/,
272+
**kwargs,
273+
) -> DataFrame: ...
267274
agg = aggregate
268275
@overload
269276
def transform(

tests/test_groupby.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,3 +1123,19 @@ def add_constant_to_mean(group: DataFrame, constant: int) -> DataFrame:
11231123
add_constant_to_mean,
11241124
constant="5", # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType]
11251125
)
1126+
1127+
1128+
def test_frame_groupby_aggregate() -> None:
1129+
"""Test DataFrame.groupby.aggregate (GH1339)."""
1130+
df = DataFrame(
1131+
{
1132+
"a": [1, 2, 3],
1133+
"b": [4, 5, 6],
1134+
"c": [7, 8, 9],
1135+
}
1136+
)
1137+
1138+
dico = {"a": ("a", "mean")}
1139+
1140+
check(assert_type(df.groupby("b").agg(a=("a", "mean")), DataFrame), DataFrame)
1141+
check(assert_type(df.groupby("b").agg(**dico), DataFrame), DataFrame)

0 commit comments

Comments
 (0)