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
Changes from 1 commit
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
15 changes: 10 additions & 5 deletions pandas/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

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

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 @@ -40,7 +43,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,
Copy link
Member

Choose a reason for hiding this comment

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

this should be Dict from typing. can you see if you can also add type parameters to Dict.

) -> Tuple[DefaultDict, Tuple[Hashable, ...], "np.ndarray"]:
Copy link
Member

Choose a reason for hiding this comment

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

What issue is this fixing?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@simonjayhawkins simonjayhawkins Apr 7, 2020

Choose a reason for hiding this comment

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

@MomIsBestFriend can you git bisect or blame to find out what's the story behind the change here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@simonjayhawkins It looks like no one can agree on the placement of this function, as it's moved around constantly.


But it looks like parts of the changes are made in #30497 while migrating from orderedict to defaultdict

Copy link
Member

Choose a reason for hiding this comment

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

normalize_keyword_aggregation is only called by aggregate in core\groupby\generic.py.

the core\groupby\generic.py module is currently excluded by check_untyped_defs and aggregate does not have type hints.

maybe worth typing aggregate as well to ensure consistency.

Copy link
Member Author

Choose a reason for hiding this comment

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

@simonjayhawkins Nice! thanks to that tip I could annotate with much more specific type hints.

"""
Normalize user-provided "named aggregation" kwargs.
Transforms from the new ``Mapping[str, NamedAgg]`` style kwargs
Expand All @@ -52,11 +57,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