Skip to content

DOC/TYP: Fixed typing and doc #33374

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

Closed
Closed
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
17 changes: 12 additions & 5 deletions pandas/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@

from collections import defaultdict
from functools import partial
from typing import Any, DefaultDict, List, Sequence, Tuple
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, List, Sequence, Tuple

from pandas._typing import Scalar

from pandas.core.dtypes.common import is_dict_like, is_list_like

import pandas.core.common as com
from pandas.core.indexes.api import Index

if TYPE_CHECKING:
import numpy as np # noqa: F401


def is_multi_agg_with_relabel(**kwargs) -> bool:
"""
Expand Down Expand Up @@ -39,7 +44,9 @@ def is_multi_agg_with_relabel(**kwargs) -> bool:
)


def normalize_keyword_aggregation(kwargs: dict) -> Tuple[dict, List[str], List[int]]:
def normalize_keyword_aggregation(
kwargs: Dict[str, str]
) -> Tuple[DefaultDict[str, List[Scalar]], Tuple[str, ...], "np.ndarray"]:
"""
Normalize user-provided "named aggregation" kwargs.
Transforms from the new ``Mapping[str, NamedAgg]`` style kwargs
Expand All @@ -51,11 +58,11 @@ def normalize_keyword_aggregation(kwargs: dict) -> Tuple[dict, List[str], List[i

Returns
-------
aggspec : dict
aggspec : collections.defaultdict of lists
The transformed kwargs.
columns : List[str]
columns : tuple
The user-provided keys.
col_idx_order : List[int]
col_idx_order : numpy.ndarray
List of columns indices.

Examples
Expand Down
8 changes: 6 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
TYPE_CHECKING,
Any,
Callable,
DefaultDict,
Dict,
FrozenSet,
Iterable,
List,
Mapping,
Optional,
Sequence,
Tuple,
Type,
Expand All @@ -30,7 +32,7 @@
import numpy as np

from pandas._libs import Timestamp, lib
from pandas._typing import FrameOrSeries
from pandas._typing import FrameOrSeries, Scalar
from pandas.util._decorators import Appender, Substitution, doc

from pandas.core.dtypes.cast import (
Expand Down Expand Up @@ -909,7 +911,9 @@ class DataFrameGroupBy(GroupBy[DataFrame]):
axis="",
)
@Appender(_shared_docs["aggregate"])
def aggregate(self, func=None, *args, **kwargs):
def aggregate(
self, func: Optional[DefaultDict[str, List[Scalar]]] = None, *args, **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can also be a list / dict of callables no?

):

relabeling = func is None and is_multi_agg_with_relabel(**kwargs)
if relabeling:
Expand Down