Skip to content

Commit 3f3b9dc

Browse files
TYP: misc typing cleanups for pandas-dev#29116
1 parent 00cb992 commit 3f3b9dc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pandas/core/aggregation.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@
1010
Callable,
1111
DefaultDict,
1212
Dict,
13+
Iterable,
1314
List,
1415
Optional,
1516
Sequence,
1617
Tuple,
1718
Union,
1819
)
1920

20-
from pandas._typing import AggFuncType, Label
21+
from pandas._typing import AggFuncType, FrameOrSeries, Label
2122

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

2425
from pandas.core.base import SpecificationError
2526
import pandas.core.common as com
2627
from pandas.core.indexes.api import Index
27-
from pandas.core.series import FrameOrSeriesUnion, Series
28+
from pandas.core.series import Series
2829

2930

3031
def reconstruct_func(
@@ -276,12 +277,13 @@ def maybe_mangle_lambdas(agg_spec: Any) -> Any:
276277

277278

278279
def relabel_result(
279-
result: FrameOrSeriesUnion,
280+
result: FrameOrSeries,
280281
func: Dict[str, List[Union[Callable, str]]],
281-
columns: Tuple,
282-
order: List[int],
282+
columns: Iterable[Label],
283+
order: Iterable[int],
283284
) -> Dict[Label, Series]:
284-
"""Internal function to reorder result if relabelling is True for
285+
"""
286+
Internal function to reorder result if relabelling is True for
285287
dataframe.agg, and return the reordered result in dict.
286288
287289
Parameters:

pandas/core/frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -7415,6 +7415,12 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):
74157415
if relabeling:
74167416
# This is to keep the order to columns occurrence unchanged, and also
74177417
# keep the order of new columns occurrence unchanged
7418+
7419+
# For the return values of reconstruct_func, if relabeling is
7420+
# False, columns and order will be None.
7421+
assert columns is not None
7422+
assert order is not None
7423+
74187424
result_in_dict = relabel_result(result, func, columns, order)
74197425
result = DataFrame(result_in_dict, index=columns)
74207426

0 commit comments

Comments
 (0)