25
25
AggObjType ,
26
26
Axis ,
27
27
FrameOrSeries ,
28
- FrameOrSeriesUnion ,
29
28
)
30
29
from pandas .util ._decorators import cache_readonly
31
30
@@ -137,10 +136,10 @@ def f(x):
137
136
self .f : AggFuncType = f
138
137
139
138
@abc .abstractmethod
140
- def apply (self ) -> FrameOrSeriesUnion :
139
+ def apply (self ) -> DataFrame | Series :
141
140
pass
142
141
143
- def agg (self ) -> FrameOrSeriesUnion | None :
142
+ def agg (self ) -> DataFrame | Series | None :
144
143
"""
145
144
Provide an implementation for the aggregators.
146
145
@@ -171,7 +170,7 @@ def agg(self) -> FrameOrSeriesUnion | None:
171
170
# caller can react
172
171
return None
173
172
174
- def transform (self ) -> FrameOrSeriesUnion :
173
+ def transform (self ) -> DataFrame | Series :
175
174
"""
176
175
Transform a DataFrame or Series.
177
176
@@ -252,7 +251,7 @@ def transform_dict_like(self, func):
252
251
253
252
func = self .normalize_dictlike_arg ("transform" , obj , func )
254
253
255
- results : dict [Hashable , FrameOrSeriesUnion ] = {}
254
+ results : dict [Hashable , DataFrame | Series ] = {}
256
255
failed_names = []
257
256
all_type_errors = True
258
257
for name , how in func .items ():
@@ -283,7 +282,7 @@ def transform_dict_like(self, func):
283
282
)
284
283
return concat (results , axis = 1 )
285
284
286
- def transform_str_or_callable (self , func ) -> FrameOrSeriesUnion :
285
+ def transform_str_or_callable (self , func ) -> DataFrame | Series :
287
286
"""
288
287
Compute transform in the case of a string or callable func
289
288
"""
@@ -305,7 +304,7 @@ def transform_str_or_callable(self, func) -> FrameOrSeriesUnion:
305
304
except Exception :
306
305
return func (obj , * args , ** kwargs )
307
306
308
- def agg_list_like (self ) -> FrameOrSeriesUnion :
307
+ def agg_list_like (self ) -> DataFrame | Series :
309
308
"""
310
309
Compute aggregation in the case of a list-like argument.
311
310
@@ -402,7 +401,7 @@ def agg_list_like(self) -> FrameOrSeriesUnion:
402
401
)
403
402
return concatenated .reindex (full_ordered_index , copy = False )
404
403
405
- def agg_dict_like (self ) -> FrameOrSeriesUnion :
404
+ def agg_dict_like (self ) -> DataFrame | Series :
406
405
"""
407
406
Compute aggregation in the case of a dict-like argument.
408
407
@@ -481,7 +480,7 @@ def agg_dict_like(self) -> FrameOrSeriesUnion:
481
480
482
481
return result
483
482
484
- def apply_str (self ) -> FrameOrSeriesUnion :
483
+ def apply_str (self ) -> DataFrame | Series :
485
484
"""
486
485
Compute apply in case of a string.
487
486
@@ -506,7 +505,7 @@ def apply_str(self) -> FrameOrSeriesUnion:
506
505
raise ValueError (f"Operation { f } does not support axis=1" )
507
506
return self ._try_aggregate_string_function (obj , f , * self .args , ** self .kwargs )
508
507
509
- def apply_multiple (self ) -> FrameOrSeriesUnion :
508
+ def apply_multiple (self ) -> DataFrame | Series :
510
509
"""
511
510
Compute apply in case of a list-like or dict-like.
512
511
@@ -518,7 +517,7 @@ def apply_multiple(self) -> FrameOrSeriesUnion:
518
517
return self .obj .aggregate (self .f , self .axis , * self .args , ** self .kwargs )
519
518
520
519
def normalize_dictlike_arg (
521
- self , how : str , obj : FrameOrSeriesUnion , func : AggFuncTypeDict
520
+ self , how : str , obj : DataFrame | Series , func : AggFuncTypeDict
522
521
) -> AggFuncTypeDict :
523
522
"""
524
523
Handler for dict-like argument.
@@ -631,7 +630,7 @@ def series_generator(self) -> Iterator[Series]:
631
630
@abc .abstractmethod
632
631
def wrap_results_for_axis (
633
632
self , results : ResType , res_index : Index
634
- ) -> FrameOrSeriesUnion :
633
+ ) -> DataFrame | Series :
635
634
pass
636
635
637
636
# ---------------------------------------------------------------
@@ -652,7 +651,7 @@ def values(self):
652
651
def dtypes (self ) -> Series :
653
652
return self .obj .dtypes
654
653
655
- def apply (self ) -> FrameOrSeriesUnion :
654
+ def apply (self ) -> DataFrame | Series :
656
655
"""compute the results"""
657
656
# dispatch to agg
658
657
if is_list_like (self .f ):
@@ -826,7 +825,7 @@ def apply_series_generator(self) -> tuple[ResType, Index]:
826
825
827
826
return results , res_index
828
827
829
- def wrap_results (self , results : ResType , res_index : Index ) -> FrameOrSeriesUnion :
828
+ def wrap_results (self , results : ResType , res_index : Index ) -> DataFrame | Series :
830
829
from pandas import Series
831
830
832
831
# see if we can infer the results
@@ -849,7 +848,7 @@ def wrap_results(self, results: ResType, res_index: Index) -> FrameOrSeriesUnion
849
848
850
849
return result
851
850
852
- def apply_str (self ) -> FrameOrSeriesUnion :
851
+ def apply_str (self ) -> DataFrame | Series :
853
852
# Caller is responsible for checking isinstance(self.f, str)
854
853
# TODO: GH#39993 - Avoid special-casing by replacing with lambda
855
854
if self .f == "size" :
@@ -880,7 +879,7 @@ def result_columns(self) -> Index:
880
879
881
880
def wrap_results_for_axis (
882
881
self , results : ResType , res_index : Index
883
- ) -> FrameOrSeriesUnion :
882
+ ) -> DataFrame | Series :
884
883
"""return the results for the rows"""
885
884
886
885
if self .result_type == "reduce" :
@@ -963,9 +962,9 @@ def result_columns(self) -> Index:
963
962
964
963
def wrap_results_for_axis (
965
964
self , results : ResType , res_index : Index
966
- ) -> FrameOrSeriesUnion :
965
+ ) -> DataFrame | Series :
967
966
"""return the results for the columns"""
968
- result : FrameOrSeriesUnion
967
+ result : DataFrame | Series
969
968
970
969
# we have requested to expand
971
970
if self .result_type == "expand" :
@@ -1019,7 +1018,7 @@ def __init__(
1019
1018
kwargs = kwargs ,
1020
1019
)
1021
1020
1022
- def apply (self ) -> FrameOrSeriesUnion :
1021
+ def apply (self ) -> DataFrame | Series :
1023
1022
obj = self .obj
1024
1023
1025
1024
if len (obj ) == 0 :
@@ -1070,7 +1069,7 @@ def apply_empty_result(self) -> Series:
1070
1069
obj , method = "apply"
1071
1070
)
1072
1071
1073
- def apply_standard (self ) -> FrameOrSeriesUnion :
1072
+ def apply_standard (self ) -> DataFrame | Series :
1074
1073
f = self .f
1075
1074
obj = self .obj
1076
1075
0 commit comments