23
23
from pandas ._typing import (
24
24
AggFuncType ,
25
25
AggFuncTypeBase ,
26
+ AggFuncTypeDict ,
26
27
Axis ,
27
28
FrameOrSeries ,
28
29
FrameOrSeriesUnion ,
@@ -442,7 +443,7 @@ def transform(
442
443
func = {col : func for col in obj }
443
444
444
445
if is_dict_like (func ):
445
- func = cast (Dict [ Label , Union [ AggFuncTypeBase , List [ AggFuncTypeBase ]]] , func )
446
+ func = cast (AggFuncTypeDict , func )
446
447
return transform_dict_like (obj , func , * args , ** kwargs )
447
448
448
449
# func is either str or callable
@@ -466,7 +467,7 @@ def transform(
466
467
467
468
def transform_dict_like (
468
469
obj : FrameOrSeries ,
469
- func : Dict [ Label , Union [ AggFuncTypeBase , List [ AggFuncTypeBase ]]] ,
470
+ func : AggFuncTypeDict ,
470
471
* args ,
471
472
** kwargs ,
472
473
):
@@ -560,7 +561,7 @@ def aggregate(
560
561
if isinstance (arg , str ):
561
562
return obj ._try_aggregate_string_function (arg , * args , ** kwargs ), None
562
563
elif is_dict_like (arg ):
563
- arg = cast (Dict [ Label , Union [ AggFuncTypeBase , List [ AggFuncTypeBase ]]] , arg )
564
+ arg = cast (AggFuncTypeDict , arg )
564
565
return agg_dict_like (obj , arg , _axis ), True
565
566
elif is_list_like (arg ):
566
567
# we require a list, but not an 'str'
@@ -672,7 +673,7 @@ def agg_list_like(
672
673
673
674
def agg_dict_like (
674
675
obj ,
675
- arg : Dict [ Label , Union [ AggFuncTypeBase , List [ AggFuncTypeBase ]]] ,
676
+ arg : AggFuncTypeDict ,
676
677
_axis : int ,
677
678
) -> FrameOrSeriesUnion :
678
679
"""
@@ -701,7 +702,7 @@ def agg_dict_like(
701
702
# eg. {'A' : ['mean']}, normalize all to
702
703
# be list-likes
703
704
if any (is_aggregator (x ) for x in arg .values ()):
704
- new_arg : Dict [ Label , Union [ AggFuncTypeBase , List [ AggFuncTypeBase ]]] = {}
705
+ new_arg : AggFuncTypeDict = {}
705
706
for k , v in arg .items ():
706
707
if not isinstance (v , (tuple , list , dict )):
707
708
new_arg [k ] = [v ]
0 commit comments