Skip to content

Commit ec4a644

Browse files
authored
REF: Remove Apply.get_result (#39082)
1 parent 237bb31 commit ec4a644

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

pandas/core/apply.py

-21
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
def frame_apply(
4242
obj: DataFrame,
43-
how: str,
4443
func: AggFuncType,
4544
axis: Axis = 0,
4645
raw: bool = False,
@@ -58,7 +57,6 @@ def frame_apply(
5857

5958
return klass(
6059
obj,
61-
how,
6260
func,
6361
raw=raw,
6462
result_type=result_type,
@@ -69,15 +67,13 @@ def frame_apply(
6967

7068
def series_apply(
7169
obj: Series,
72-
how: str,
7370
func: AggFuncType,
7471
convert_dtype: bool = True,
7572
args=None,
7673
kwds=None,
7774
) -> SeriesApply:
7875
return SeriesApply(
7976
obj,
80-
how,
8177
func,
8278
convert_dtype,
8379
args,
@@ -91,16 +87,13 @@ class Apply(metaclass=abc.ABCMeta):
9187
def __init__(
9288
self,
9389
obj: FrameOrSeriesUnion,
94-
how: str,
9590
func,
9691
raw: bool,
9792
result_type: Optional[str],
9893
args,
9994
kwds,
10095
):
101-
assert how in ("apply", "agg")
10296
self.obj = obj
103-
self.how = how
10497
self.raw = raw
10598
self.args = args or ()
10699
self.kwds = kwds or {}
@@ -132,12 +125,6 @@ def f(x):
132125
def index(self) -> Index:
133126
return self.obj.index
134127

135-
def get_result(self):
136-
if self.how == "apply":
137-
return self.apply()
138-
else:
139-
return self.agg()
140-
141128
@abc.abstractmethod
142129
def apply(self) -> FrameOrSeriesUnion:
143130
pass
@@ -234,12 +221,6 @@ def dtypes(self) -> Series:
234221
def agg_axis(self) -> Index:
235222
return self.obj._get_agg_axis(self.axis)
236223

237-
def get_result(self):
238-
if self.how == "apply":
239-
return self.apply()
240-
else:
241-
return self.agg()
242-
243224
def apply(self) -> FrameOrSeriesUnion:
244225
""" compute the results """
245226
# dispatch to agg
@@ -570,7 +551,6 @@ class SeriesApply(Apply):
570551
def __init__(
571552
self,
572553
obj: Series,
573-
how: str,
574554
func: AggFuncType,
575555
convert_dtype: bool,
576556
args,
@@ -580,7 +560,6 @@ def __init__(
580560

581561
super().__init__(
582562
obj,
583-
how,
584563
func,
585564
raw=False,
586565
result_type=None,

pandas/core/frame.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -7646,13 +7646,12 @@ def _aggregate(self, arg, axis: Axis = 0, *args, **kwargs):
76467646

76477647
op = frame_apply(
76487648
self if axis == 0 else self.T,
7649-
how="agg",
76507649
func=arg,
76517650
axis=0,
76527651
args=args,
76537652
kwds=kwargs,
76547653
)
7655-
result, how = op.get_result()
7654+
result, how = op.agg()
76567655

76577656
if axis == 1:
76587657
# NDFrame.aggregate returns a tuple, and we need to transpose
@@ -7819,15 +7818,14 @@ def apply(
78197818

78207819
op = frame_apply(
78217820
self,
7822-
how="apply",
78237821
func=func,
78247822
axis=axis,
78257823
raw=raw,
78267824
result_type=result_type,
78277825
args=args,
78287826
kwds=kwds,
78297827
)
7830-
return op.get_result()
7828+
return op.apply()
78317829

78327830
def applymap(
78337831
self, func: PythonFuncType, na_action: Optional[str] = None

pandas/core/series.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3944,8 +3944,8 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):
39443944
if func is None:
39453945
func = dict(kwargs.items())
39463946

3947-
op = series_apply(self, "agg", func, args=args, kwds=kwargs)
3948-
result, how = op.get_result()
3947+
op = series_apply(self, func, args=args, kwds=kwargs)
3948+
result, how = op.agg()
39493949
if result is None:
39503950

39513951
# we can be called from an inner function which
@@ -4083,8 +4083,8 @@ def apply(
40834083
Helsinki 2.484907
40844084
dtype: float64
40854085
"""
4086-
op = series_apply(self, "apply", func, convert_dtype, args, kwds)
4087-
return op.get_result()
4086+
op = series_apply(self, func, convert_dtype, args, kwds)
4087+
return op.apply()
40884088

40894089
def _reduce(
40904090
self,

0 commit comments

Comments
 (0)