Skip to content

CLN: Refactor groupby._make_wrapper #48400

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 6 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 5 additions & 3 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,12 @@ def apply_str(self) -> DataFrame | Series:
func = getattr(obj, f, None)
if callable(func):
sig = inspect.getfullargspec(func)
if "axis" in sig.args:
self.kwargs["axis"] = self.axis
elif self.axis != 0:
if self.axis != 0 and (
"axis" not in sig.args or f in ("corrwith", "mad", "skew")
):
raise ValueError(f"Operation {f} does not support axis=1")
elif "axis" in sig.args:
self.kwargs["axis"] = self.axis
return self._try_aggregate_string_function(obj, f, *self.args, **self.kwargs)

def apply_multiple(self) -> DataFrame | Series:
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11657,10 +11657,8 @@ def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs):

setattr(cls, "all", all)

# error: Argument 1 to "doc" has incompatible type "Optional[str]"; expected
# "Union[str, Callable[..., Any]]"
@doc(
NDFrame.mad.__doc__, # type: ignore[arg-type]
NDFrame.mad.__doc__,
desc="Return the mean absolute deviation of the values "
"over the requested axis.",
name1=name1,
Expand Down
34 changes: 1 addition & 33 deletions pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
Provide basic components for groupby. These definitions
hold the allowlist of methods that are exposed on the
SeriesGroupBy and the DataFrameGroupBy objects.
Provide basic components for groupby.
"""
from __future__ import annotations

Expand All @@ -22,36 +20,6 @@ class OutputKey:
# forwarding methods from NDFrames
plotting_methods = frozenset(["plot", "hist"])

common_apply_allowlist = (
frozenset(
[
"quantile",
"fillna",
"mad",
"take",
"idxmax",
"idxmin",
"tshift",
"skew",
"corr",
"cov",
"diff",
]
)
| plotting_methods
)

series_apply_allowlist: frozenset[str] = (
common_apply_allowlist
| frozenset(
{"nlargest", "nsmallest", "is_monotonic_increasing", "is_monotonic_decreasing"}
)
) | frozenset(["dtype", "unique"])

dataframe_apply_allowlist: frozenset[str] = common_apply_allowlist | frozenset(
["dtypes", "corrwith"]
)

# cythonized transformations or canned "agg+broadcast", which do not
# require postprocessing of the result by transform.
cythonized_kernels = frozenset(["cumprod", "cumsum", "shift", "cummin", "cummax"])
Expand Down
Loading