Skip to content

CLN: Remove unnecessary block in apply_str #58077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down