Skip to content

Commit 8c62fbb

Browse files
authored
CLN: Remove _axis from apply (#40261)
1 parent cb88d47 commit 8c62fbb

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

pandas/core/apply.py

+4-25
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,15 @@ def agg(self) -> Optional[FrameOrSeriesUnion]:
166166
args = self.args
167167
kwargs = self.kwargs
168168

169-
_axis = kwargs.pop("_axis", None)
170-
if _axis is None:
171-
_axis = getattr(obj, "axis", 0)
172-
173169
result = self.maybe_apply_str()
174170
if result is not None:
175171
return result
176172

177173
if is_dict_like(arg):
178-
return self.agg_dict_like(_axis)
174+
return self.agg_dict_like()
179175
elif is_list_like(arg):
180176
# we require a list, but not a 'str'
181-
return self.agg_list_like(_axis=_axis)
177+
return self.agg_list_like()
182178

183179
if callable(arg):
184180
f = obj._get_cython_func(arg)
@@ -317,15 +313,10 @@ def transform_str_or_callable(self, func) -> FrameOrSeriesUnion:
317313
except Exception:
318314
return func(obj, *args, **kwargs)
319315

320-
def agg_list_like(self, _axis: int) -> FrameOrSeriesUnion:
316+
def agg_list_like(self) -> FrameOrSeriesUnion:
321317
"""
322318
Compute aggregation in the case of a list-like argument.
323319
324-
Parameters
325-
----------
326-
_axis : int, 0 or 1
327-
Axis to compute aggregation on.
328-
329320
Returns
330321
-------
331322
Result of aggregation.
@@ -335,9 +326,6 @@ def agg_list_like(self, _axis: int) -> FrameOrSeriesUnion:
335326
obj = self.obj
336327
arg = cast(List[AggFuncTypeBase], self.f)
337328

338-
if _axis != 0:
339-
raise NotImplementedError("axis other than 0 is not supported")
340-
341329
if obj._selected_obj.ndim == 1:
342330
selected_obj = obj._selected_obj
343331
else:
@@ -404,15 +392,10 @@ def agg_list_like(self, _axis: int) -> FrameOrSeriesUnion:
404392
) from err
405393
return result
406394

407-
def agg_dict_like(self, _axis: int) -> FrameOrSeriesUnion:
395+
def agg_dict_like(self) -> FrameOrSeriesUnion:
408396
"""
409397
Compute aggregation in the case of a dict-like argument.
410398
411-
Parameters
412-
----------
413-
_axis : int, 0 or 1
414-
Axis to compute aggregation on.
415-
416399
Returns
417400
-------
418401
Result of aggregation.
@@ -422,9 +405,6 @@ def agg_dict_like(self, _axis: int) -> FrameOrSeriesUnion:
422405
obj = self.obj
423406
arg = cast(AggFuncTypeDict, self.f)
424407

425-
if _axis != 0: # pragma: no cover
426-
raise ValueError("Can only pass dict with axis=0")
427-
428408
selected_obj = obj._selected_obj
429409

430410
arg = self.normalize_dictlike_arg("agg", selected_obj, arg)
@@ -1007,7 +987,6 @@ def agg(self):
1007987

1008988
# we can be called from an inner function which
1009989
# passes this meta-data
1010-
kwargs.pop("_axis", None)
1011990
kwargs.pop("_level", None)
1012991

1013992
# try a regular apply, this evaluates lambdas

pandas/core/groupby/generic.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
10231023

10241024
# try to treat as if we are passing a list
10251025
try:
1026-
result = GroupByApply(
1027-
self, [func], args=(), kwargs={"_axis": self.axis}
1028-
).agg()
1026+
result = GroupByApply(self, [func], args=(), kwargs={}).agg()
10291027

10301028
# select everything except for the last level, which is the one
10311029
# containing the name of the function(s), see GH 32040

0 commit comments

Comments
 (0)