2525 AggObjType ,
2626 Axis ,
2727 FrameOrSeries ,
28- FrameOrSeriesUnion ,
2928)
3029from pandas .util ._decorators import cache_readonly
3130
@@ -137,10 +136,10 @@ def f(x):
137136 self .f : AggFuncType = f
138137
139138 @abc .abstractmethod
140- def apply (self ) -> FrameOrSeriesUnion :
139+ def apply (self ) -> DataFrame | Series :
141140 pass
142141
143- def agg (self ) -> FrameOrSeriesUnion | None :
142+ def agg (self ) -> DataFrame | Series | None :
144143 """
145144 Provide an implementation for the aggregators.
146145
@@ -171,7 +170,7 @@ def agg(self) -> FrameOrSeriesUnion | None:
171170 # caller can react
172171 return None
173172
174- def transform (self ) -> FrameOrSeriesUnion :
173+ def transform (self ) -> DataFrame | Series :
175174 """
176175 Transform a DataFrame or Series.
177176
@@ -252,7 +251,7 @@ def transform_dict_like(self, func):
252251
253252 func = self .normalize_dictlike_arg ("transform" , obj , func )
254253
255- results : dict [Hashable , FrameOrSeriesUnion ] = {}
254+ results : dict [Hashable , DataFrame | Series ] = {}
256255 failed_names = []
257256 all_type_errors = True
258257 for name , how in func .items ():
@@ -283,7 +282,7 @@ def transform_dict_like(self, func):
283282 )
284283 return concat (results , axis = 1 )
285284
286- def transform_str_or_callable (self , func ) -> FrameOrSeriesUnion :
285+ def transform_str_or_callable (self , func ) -> DataFrame | Series :
287286 """
288287 Compute transform in the case of a string or callable func
289288 """
@@ -305,7 +304,7 @@ def transform_str_or_callable(self, func) -> FrameOrSeriesUnion:
305304 except Exception :
306305 return func (obj , * args , ** kwargs )
307306
308- def agg_list_like (self ) -> FrameOrSeriesUnion :
307+ def agg_list_like (self ) -> DataFrame | Series :
309308 """
310309 Compute aggregation in the case of a list-like argument.
311310
@@ -402,7 +401,7 @@ def agg_list_like(self) -> FrameOrSeriesUnion:
402401 )
403402 return concatenated .reindex (full_ordered_index , copy = False )
404403
405- def agg_dict_like (self ) -> FrameOrSeriesUnion :
404+ def agg_dict_like (self ) -> DataFrame | Series :
406405 """
407406 Compute aggregation in the case of a dict-like argument.
408407
@@ -481,7 +480,7 @@ def agg_dict_like(self) -> FrameOrSeriesUnion:
481480
482481 return result
483482
484- def apply_str (self ) -> FrameOrSeriesUnion :
483+ def apply_str (self ) -> DataFrame | Series :
485484 """
486485 Compute apply in case of a string.
487486
@@ -506,7 +505,7 @@ def apply_str(self) -> FrameOrSeriesUnion:
506505 raise ValueError (f"Operation { f } does not support axis=1" )
507506 return self ._try_aggregate_string_function (obj , f , * self .args , ** self .kwargs )
508507
509- def apply_multiple (self ) -> FrameOrSeriesUnion :
508+ def apply_multiple (self ) -> DataFrame | Series :
510509 """
511510 Compute apply in case of a list-like or dict-like.
512511
@@ -518,7 +517,7 @@ def apply_multiple(self) -> FrameOrSeriesUnion:
518517 return self .obj .aggregate (self .f , self .axis , * self .args , ** self .kwargs )
519518
520519 def normalize_dictlike_arg (
521- self , how : str , obj : FrameOrSeriesUnion , func : AggFuncTypeDict
520+ self , how : str , obj : DataFrame | Series , func : AggFuncTypeDict
522521 ) -> AggFuncTypeDict :
523522 """
524523 Handler for dict-like argument.
@@ -631,7 +630,7 @@ def series_generator(self) -> Iterator[Series]:
631630 @abc .abstractmethod
632631 def wrap_results_for_axis (
633632 self , results : ResType , res_index : Index
634- ) -> FrameOrSeriesUnion :
633+ ) -> DataFrame | Series :
635634 pass
636635
637636 # ---------------------------------------------------------------
@@ -652,7 +651,7 @@ def values(self):
652651 def dtypes (self ) -> Series :
653652 return self .obj .dtypes
654653
655- def apply (self ) -> FrameOrSeriesUnion :
654+ def apply (self ) -> DataFrame | Series :
656655 """compute the results"""
657656 # dispatch to agg
658657 if is_list_like (self .f ):
@@ -826,7 +825,7 @@ def apply_series_generator(self) -> tuple[ResType, Index]:
826825
827826 return results , res_index
828827
829- def wrap_results (self , results : ResType , res_index : Index ) -> FrameOrSeriesUnion :
828+ def wrap_results (self , results : ResType , res_index : Index ) -> DataFrame | Series :
830829 from pandas import Series
831830
832831 # see if we can infer the results
@@ -849,7 +848,7 @@ def wrap_results(self, results: ResType, res_index: Index) -> FrameOrSeriesUnion
849848
850849 return result
851850
852- def apply_str (self ) -> FrameOrSeriesUnion :
851+ def apply_str (self ) -> DataFrame | Series :
853852 # Caller is responsible for checking isinstance(self.f, str)
854853 # TODO: GH#39993 - Avoid special-casing by replacing with lambda
855854 if self .f == "size" :
@@ -880,7 +879,7 @@ def result_columns(self) -> Index:
880879
881880 def wrap_results_for_axis (
882881 self , results : ResType , res_index : Index
883- ) -> FrameOrSeriesUnion :
882+ ) -> DataFrame | Series :
884883 """return the results for the rows"""
885884
886885 if self .result_type == "reduce" :
@@ -963,9 +962,9 @@ def result_columns(self) -> Index:
963962
964963 def wrap_results_for_axis (
965964 self , results : ResType , res_index : Index
966- ) -> FrameOrSeriesUnion :
965+ ) -> DataFrame | Series :
967966 """return the results for the columns"""
968- result : FrameOrSeriesUnion
967+ result : DataFrame | Series
969968
970969 # we have requested to expand
971970 if self .result_type == "expand" :
@@ -1019,7 +1018,7 @@ def __init__(
10191018 kwargs = kwargs ,
10201019 )
10211020
1022- def apply (self ) -> FrameOrSeriesUnion :
1021+ def apply (self ) -> DataFrame | Series :
10231022 obj = self .obj
10241023
10251024 if len (obj ) == 0 :
@@ -1070,7 +1069,7 @@ def apply_empty_result(self) -> Series:
10701069 obj , method = "apply"
10711070 )
10721071
1073- def apply_standard (self ) -> FrameOrSeriesUnion :
1072+ def apply_standard (self ) -> DataFrame | Series :
10741073 f = self .f
10751074 obj = self .obj
10761075
0 commit comments