From 3d83d6d2644540db010b102f240033b57ab8f43f Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Fri, 5 Mar 2021 17:49:44 -0500 Subject: [PATCH] CLN: Remove _axis from apply --- pandas/core/apply.py | 29 ++++------------------------- pandas/core/groupby/generic.py | 4 +--- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index c159abe55b38c..cccd88ccb7a1e 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -166,19 +166,15 @@ def agg(self) -> Optional[FrameOrSeriesUnion]: args = self.args kwargs = self.kwargs - _axis = kwargs.pop("_axis", None) - if _axis is None: - _axis = getattr(obj, "axis", 0) - result = self.maybe_apply_str() if result is not None: return result if is_dict_like(arg): - return self.agg_dict_like(_axis) + return self.agg_dict_like() elif is_list_like(arg): # we require a list, but not a 'str' - return self.agg_list_like(_axis=_axis) + return self.agg_list_like() if callable(arg): f = obj._get_cython_func(arg) @@ -317,15 +313,10 @@ def transform_str_or_callable(self, func) -> FrameOrSeriesUnion: except Exception: return func(obj, *args, **kwargs) - def agg_list_like(self, _axis: int) -> FrameOrSeriesUnion: + def agg_list_like(self) -> FrameOrSeriesUnion: """ Compute aggregation in the case of a list-like argument. - Parameters - ---------- - _axis : int, 0 or 1 - Axis to compute aggregation on. - Returns ------- Result of aggregation. @@ -335,9 +326,6 @@ def agg_list_like(self, _axis: int) -> FrameOrSeriesUnion: obj = self.obj arg = cast(List[AggFuncTypeBase], self.f) - if _axis != 0: - raise NotImplementedError("axis other than 0 is not supported") - if obj._selected_obj.ndim == 1: selected_obj = obj._selected_obj else: @@ -404,15 +392,10 @@ def agg_list_like(self, _axis: int) -> FrameOrSeriesUnion: ) from err return result - def agg_dict_like(self, _axis: int) -> FrameOrSeriesUnion: + def agg_dict_like(self) -> FrameOrSeriesUnion: """ Compute aggregation in the case of a dict-like argument. - Parameters - ---------- - _axis : int, 0 or 1 - Axis to compute aggregation on. - Returns ------- Result of aggregation. @@ -422,9 +405,6 @@ def agg_dict_like(self, _axis: int) -> FrameOrSeriesUnion: obj = self.obj arg = cast(AggFuncTypeDict, self.f) - if _axis != 0: # pragma: no cover - raise ValueError("Can only pass dict with axis=0") - selected_obj = obj._selected_obj arg = self.normalize_dictlike_arg("agg", selected_obj, arg) @@ -1007,7 +987,6 @@ def agg(self): # we can be called from an inner function which # passes this meta-data - kwargs.pop("_axis", None) kwargs.pop("_level", None) # try a regular apply, this evaluates lambdas diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 2de5e81360a93..b95a3455ca905 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1023,9 +1023,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs) # try to treat as if we are passing a list try: - result = GroupByApply( - self, [func], args=(), kwargs={"_axis": self.axis} - ).agg() + result = GroupByApply(self, [func], args=(), kwargs={}).agg() # select everything except for the last level, which is the one # containing the name of the function(s), see GH 32040