diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 874b40f224a26..a618e2a92551d 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -40,7 +40,6 @@ def frame_apply( obj: DataFrame, - how: str, func: AggFuncType, axis: Axis = 0, raw: bool = False, @@ -58,7 +57,6 @@ def frame_apply( return klass( obj, - how, func, raw=raw, result_type=result_type, @@ -69,7 +67,6 @@ def frame_apply( def series_apply( obj: Series, - how: str, func: AggFuncType, convert_dtype: bool = True, args=None, @@ -77,7 +74,6 @@ def series_apply( ) -> SeriesApply: return SeriesApply( obj, - how, func, convert_dtype, args, @@ -91,16 +87,13 @@ class Apply(metaclass=abc.ABCMeta): def __init__( self, obj: FrameOrSeriesUnion, - how: str, func, raw: bool, result_type: Optional[str], args, kwds, ): - assert how in ("apply", "agg") self.obj = obj - self.how = how self.raw = raw self.args = args or () self.kwds = kwds or {} @@ -132,12 +125,6 @@ def f(x): def index(self) -> Index: return self.obj.index - def get_result(self): - if self.how == "apply": - return self.apply() - else: - return self.agg() - @abc.abstractmethod def apply(self) -> FrameOrSeriesUnion: pass @@ -234,12 +221,6 @@ def dtypes(self) -> Series: def agg_axis(self) -> Index: return self.obj._get_agg_axis(self.axis) - def get_result(self): - if self.how == "apply": - return self.apply() - else: - return self.agg() - def apply(self) -> FrameOrSeriesUnion: """ compute the results """ # dispatch to agg @@ -570,7 +551,6 @@ class SeriesApply(Apply): def __init__( self, obj: Series, - how: str, func: AggFuncType, convert_dtype: bool, args, @@ -580,7 +560,6 @@ def __init__( super().__init__( obj, - how, func, raw=False, result_type=None, diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e65e9302dd4d5..1d8280ae3b2f1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7646,13 +7646,12 @@ def _aggregate(self, arg, axis: Axis = 0, *args, **kwargs): op = frame_apply( self if axis == 0 else self.T, - how="agg", func=arg, axis=0, args=args, kwds=kwargs, ) - result, how = op.get_result() + result, how = op.agg() if axis == 1: # NDFrame.aggregate returns a tuple, and we need to transpose @@ -7819,7 +7818,6 @@ def apply( op = frame_apply( self, - how="apply", func=func, axis=axis, raw=raw, @@ -7827,7 +7825,7 @@ def apply( args=args, kwds=kwds, ) - return op.get_result() + return op.apply() def applymap( self, func: PythonFuncType, na_action: Optional[str] = None diff --git a/pandas/core/series.py b/pandas/core/series.py index 6586ac8b01840..b90ec00fc1d67 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3944,8 +3944,8 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): if func is None: func = dict(kwargs.items()) - op = series_apply(self, "agg", func, args=args, kwds=kwargs) - result, how = op.get_result() + op = series_apply(self, func, args=args, kwds=kwargs) + result, how = op.agg() if result is None: # we can be called from an inner function which @@ -4077,8 +4077,8 @@ def apply(self, func, convert_dtype=True, args=(), **kwds): Helsinki 2.484907 dtype: float64 """ - op = series_apply(self, "apply", func, convert_dtype, args, kwds) - return op.get_result() + op = series_apply(self, func, convert_dtype, args, kwds) + return op.apply() def _reduce( self,