1212 Any ,
1313 Callable ,
1414 DefaultDict ,
15- Dict ,
1615 Hashable ,
1716 Iterable ,
18- List ,
19- Optional ,
2017 Sequence ,
21- Tuple ,
22- Union ,
2318)
2419
2520from pandas ._typing import (
4237
4338
4439def reconstruct_func (
45- func : Optional [ AggFuncType ] , ** kwargs
46- ) -> Tuple [bool , Optional [ AggFuncType ], Optional [ List [ str ]], Optional [ List [ int ]] ]:
40+ func : AggFuncType | None , ** kwargs
41+ ) -> tuple [bool , AggFuncType | None , list [ str ] | None , list [ int ] | None ]:
4742 """
4843 This is the internal function to reconstruct func given if there is relabeling
4944 or not and also normalize the keyword to get new order of columns.
@@ -81,8 +76,8 @@ def reconstruct_func(
8176 (False, 'min', None, None)
8277 """
8378 relabeling = func is None and is_multi_agg_with_relabel (** kwargs )
84- columns : Optional [ List [ str ]] = None
85- order : Optional [ List [ int ]] = None
79+ columns : list [ str ] | None = None
80+ order : list [ int ] | None = None
8681
8782 if not relabeling :
8883 if isinstance (func , list ) and len (func ) > len (set (func )):
@@ -129,7 +124,7 @@ def is_multi_agg_with_relabel(**kwargs) -> bool:
129124 )
130125
131126
132- def normalize_keyword_aggregation (kwargs : dict ) -> Tuple [dict , List [str ], List [int ]]:
127+ def normalize_keyword_aggregation (kwargs : dict ) -> tuple [dict , list [str ], list [int ]]:
133128 """
134129 Normalize user-provided "named aggregation" kwargs.
135130 Transforms from the new ``Mapping[str, NamedAgg]`` style kwargs
@@ -187,8 +182,8 @@ def normalize_keyword_aggregation(kwargs: dict) -> Tuple[dict, List[str], List[i
187182
188183
189184def _make_unique_kwarg_list (
190- seq : Sequence [Tuple [Any , Any ]]
191- ) -> Sequence [Tuple [Any , Any ]]:
185+ seq : Sequence [tuple [Any , Any ]]
186+ ) -> Sequence [tuple [Any , Any ]]:
192187 """
193188 Uniquify aggfunc name of the pairs in the order list
194189
@@ -292,10 +287,10 @@ def maybe_mangle_lambdas(agg_spec: Any) -> Any:
292287
293288def relabel_result (
294289 result : FrameOrSeries ,
295- func : Dict [str , List [ Union [ Callable , str ] ]],
290+ func : dict [str , list [ Callable | str ]],
296291 columns : Iterable [Hashable ],
297292 order : Iterable [int ],
298- ) -> Dict [Hashable , Series ]:
293+ ) -> dict [Hashable , Series ]:
299294 """
300295 Internal function to reorder result if relabelling is True for
301296 dataframe.agg, and return the reordered result in dict.
@@ -322,7 +317,7 @@ def relabel_result(
322317 reordered_indexes = [
323318 pair [0 ] for pair in sorted (zip (columns , order ), key = lambda t : t [1 ])
324319 ]
325- reordered_result_in_dict : Dict [Hashable , Series ] = {}
320+ reordered_result_in_dict : dict [Hashable , Series ] = {}
326321 idx = 0
327322
328323 reorder_mask = not isinstance (result , ABCSeries ) and len (result .columns ) > 1
@@ -366,7 +361,7 @@ def relabel_result(
366361
367362def validate_func_kwargs (
368363 kwargs : dict ,
369- ) -> Tuple [ List [str ], List [ Union [ str , Callable [..., Any ] ]]]:
364+ ) -> tuple [ list [str ], list [ str | Callable [..., Any ]]]:
370365 """
371366 Validates types of user-provided "named aggregation" kwargs.
372367 `TypeError` is raised if aggfunc is not `str` or callable.
0 commit comments