Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading