From a67b3afd4fe9cc49ba17c068a2b6f16a68f21acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Thu, 21 Aug 2025 21:47:03 -0400 Subject: [PATCH] GH1339 Allow DataFrame.groupby.aggregate with unpacked dictionary --- pandas-stubs/core/groupby/generic.pyi | 7 +++++++ tests/test_groupby.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pandas-stubs/core/groupby/generic.pyi b/pandas-stubs/core/groupby/generic.pyi index 75430c052..2ff941145 100644 --- a/pandas-stubs/core/groupby/generic.pyi +++ b/pandas-stubs/core/groupby/generic.pyi @@ -264,6 +264,13 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]): engine_kwargs: WindowingEngineKwargs = ..., **kwargs, ) -> DataFrame: ... + @overload + def aggregate( + self, + func: AggFuncTypeFrame | None = None, + /, + **kwargs, + ) -> DataFrame: ... agg = aggregate @overload def transform( diff --git a/tests/test_groupby.py b/tests/test_groupby.py index a35177234..2e478b3c0 100644 --- a/tests/test_groupby.py +++ b/tests/test_groupby.py @@ -1123,3 +1123,19 @@ def add_constant_to_mean(group: DataFrame, constant: int) -> DataFrame: add_constant_to_mean, constant="5", # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType] ) + + +def test_frame_groupby_aggregate() -> None: + """Test DataFrame.groupby.aggregate (GH1339).""" + df = DataFrame( + { + "a": [1, 2, 3], + "b": [4, 5, 6], + "c": [7, 8, 9], + } + ) + + dico = {"a": ("a", "mean")} + + check(assert_type(df.groupby("b").agg(a=("a", "mean")), DataFrame), DataFrame) + check(assert_type(df.groupby("b").agg(**dico), DataFrame), DataFrame)