Skip to content

TYP: misc typing cleanups for #29116 #35953

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

Merged
merged 1 commit into from
Aug 30, 2020
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
14 changes: 8 additions & 6 deletions pandas/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
Callable,
DefaultDict,
Dict,
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
)

from pandas._typing import AggFuncType, Label
from pandas._typing import AggFuncType, FrameOrSeries, Label

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

from pandas.core.base import SpecificationError
import pandas.core.common as com
from pandas.core.indexes.api import Index
from pandas.core.series import FrameOrSeriesUnion, Series
from pandas.core.series import Series


def reconstruct_func(
Expand Down Expand Up @@ -276,12 +277,13 @@ def maybe_mangle_lambdas(agg_spec: Any) -> Any:


def relabel_result(
result: FrameOrSeriesUnion,
result: FrameOrSeries,
func: Dict[str, List[Union[Callable, str]]],
columns: Tuple,
order: List[int],
columns: Iterable[Label],
order: Iterable[int],
) -> Dict[Label, Series]:
"""Internal function to reorder result if relabelling is True for
"""
Internal function to reorder result if relabelling is True for
dataframe.agg, and return the reordered result in dict.

Parameters:
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7415,6 +7415,12 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):
if relabeling:
# This is to keep the order to columns occurrence unchanged, and also
# keep the order of new columns occurrence unchanged

# For the return values of reconstruct_func, if relabeling is
# False, columns and order will be None.
assert columns is not None
assert order is not None

result_in_dict = relabel_result(result, func, columns, order)
result = DataFrame(result_in_dict, index=columns)

Expand Down