From dc5249c4671f896eeabeaffe7b8673e99e09d291 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 29 Mar 2024 15:25:46 -0400 Subject: [PATCH] CLN: Remove unnecessary block in apply_str --- pandas/core/apply.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index de2fd9394e2fa..e8df24850f7a8 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -564,22 +564,10 @@ def apply_str(self) -> DataFrame | Series: "axis" not in arg_names or func in ("corrwith", "skew") ): raise ValueError(f"Operation {func} does not support axis=1") - if "axis" in arg_names: - if isinstance(obj, (SeriesGroupBy, DataFrameGroupBy)): - # Try to avoid FutureWarning for deprecated axis keyword; - # If self.axis matches the axis we would get by not passing - # axis, we safely exclude the keyword. - - default_axis = 0 - if func in ["idxmax", "idxmin"]: - # DataFrameGroupBy.idxmax, idxmin axis defaults to self.axis, - # whereas other axis keywords default to 0 - default_axis = self.obj.axis - - if default_axis != self.axis: - self.kwargs["axis"] = self.axis - else: - self.kwargs["axis"] = self.axis + if "axis" in arg_names and not isinstance( + obj, (SeriesGroupBy, DataFrameGroupBy) + ): + self.kwargs["axis"] = self.axis return self._apply_str(obj, func, *self.args, **self.kwargs) def apply_list_or_dict_like(self) -> DataFrame | Series: