Skip to content

Commit

Permalink
CLN: Remove _axis from apply (#40261)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhshadrach committed Mar 8, 2021
1 parent cb88d47 commit 8c62fbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
29 changes: 4 additions & 25 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c62fbb

Please sign in to comment.