Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling df.agg with scalar dict values #861

Merged
merged 1 commit into from
Feb 12, 2024
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
9 changes: 6 additions & 3 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ from pandas._typing import (
S1,
AggFuncTypeBase,
AggFuncTypeDictFrame,
AggFuncTypeDictSeries,
AggFuncTypeFrame,
AnyArrayLike,
ArrayLike,
Expand Down Expand Up @@ -1139,7 +1140,9 @@ class DataFrame(NDFrame, OpsMixin):
) -> DataFrame: ...
def diff(self, periods: int = ..., axis: Axis = ...) -> DataFrame: ...
@overload
def agg(self, func: AggFuncTypeBase, axis: Axis = ..., **kwargs) -> Series: ...
def agg( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
self, func: AggFuncTypeBase | AggFuncTypeDictSeries, axis: Axis = ..., **kwargs
) -> Series: ...
@overload
def agg(
self,
Expand All @@ -1148,8 +1151,8 @@ class DataFrame(NDFrame, OpsMixin):
**kwargs,
) -> DataFrame: ...
@overload
def aggregate(
self, func: AggFuncTypeBase, axis: Axis = ..., **kwargs
def aggregate( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
self, func: AggFuncTypeBase | AggFuncTypeDictSeries, axis: Axis = ..., **kwargs
) -> Series: ...
@overload
def aggregate(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,10 @@ def test_types_agg() -> None:
assert_type(df.agg({"A": ["min", "max"], "B": "min"}), pd.DataFrame),
pd.DataFrame,
)
check(assert_type(df.agg({"A": ["mean"]}), pd.DataFrame), pd.DataFrame)
check(assert_type(df.agg("mean", axis=1), pd.Series), pd.Series)
check(assert_type(df.agg({"A": "mean"}), pd.Series), pd.Series)
check(assert_type(df.agg({"A": "mean", "B": "sum"}), pd.Series), pd.Series)


def test_types_aggregate() -> None:
Expand All @@ -1290,6 +1293,10 @@ def test_types_aggregate() -> None:
assert_type(df.aggregate({"A": ["min", "max"], "B": "min"}), pd.DataFrame),
pd.DataFrame,
)
check(assert_type(df.aggregate({"A": ["mean"]}), pd.DataFrame), pd.DataFrame)
check(assert_type(df.aggregate("mean", axis=1), pd.Series), pd.Series)
check(assert_type(df.aggregate({"A": "mean"}), pd.Series), pd.Series)
check(assert_type(df.aggregate({"A": "mean", "B": "sum"}), pd.Series), pd.Series)


def test_types_transform() -> None:
Expand Down
Loading