12
12
Any ,
13
13
Callable ,
14
14
DefaultDict ,
15
- Dict ,
16
15
Hashable ,
17
16
Iterable ,
18
- List ,
19
- Optional ,
20
17
Sequence ,
21
- Tuple ,
22
- Union ,
23
18
)
24
19
25
20
from pandas ._typing import (
42
37
43
38
44
39
def 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 ]:
47
42
"""
48
43
This is the internal function to reconstruct func given if there is relabeling
49
44
or not and also normalize the keyword to get new order of columns.
@@ -81,8 +76,8 @@ def reconstruct_func(
81
76
(False, 'min', None, None)
82
77
"""
83
78
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
86
81
87
82
if not relabeling :
88
83
if isinstance (func , list ) and len (func ) > len (set (func )):
@@ -129,7 +124,7 @@ def is_multi_agg_with_relabel(**kwargs) -> bool:
129
124
)
130
125
131
126
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 ]]:
133
128
"""
134
129
Normalize user-provided "named aggregation" kwargs.
135
130
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
187
182
188
183
189
184
def _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 ]]:
192
187
"""
193
188
Uniquify aggfunc name of the pairs in the order list
194
189
@@ -292,10 +287,10 @@ def maybe_mangle_lambdas(agg_spec: Any) -> Any:
292
287
293
288
def relabel_result (
294
289
result : FrameOrSeries ,
295
- func : Dict [str , List [ Union [ Callable , str ] ]],
290
+ func : dict [str , list [ Callable | str ]],
296
291
columns : Iterable [Hashable ],
297
292
order : Iterable [int ],
298
- ) -> Dict [Hashable , Series ]:
293
+ ) -> dict [Hashable , Series ]:
299
294
"""
300
295
Internal function to reorder result if relabelling is True for
301
296
dataframe.agg, and return the reordered result in dict.
@@ -322,7 +317,7 @@ def relabel_result(
322
317
reordered_indexes = [
323
318
pair [0 ] for pair in sorted (zip (columns , order ), key = lambda t : t [1 ])
324
319
]
325
- reordered_result_in_dict : Dict [Hashable , Series ] = {}
320
+ reordered_result_in_dict : dict [Hashable , Series ] = {}
326
321
idx = 0
327
322
328
323
reorder_mask = not isinstance (result , ABCSeries ) and len (result .columns ) > 1
@@ -366,7 +361,7 @@ def relabel_result(
366
361
367
362
def validate_func_kwargs (
368
363
kwargs : dict ,
369
- ) -> Tuple [ List [str ], List [ Union [ str , Callable [..., Any ] ]]]:
364
+ ) -> tuple [ list [str ], list [ str | Callable [..., Any ]]]:
370
365
"""
371
366
Validates types of user-provided "named aggregation" kwargs.
372
367
`TypeError` is raised if aggfunc is not `str` or callable.
0 commit comments