Skip to content

REF: Use _python_apply_general internally #52342

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 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2685,7 +2685,9 @@ def dtypes(self) -> Series:
)

# error: Incompatible return value type (got "DataFrame", expected "Series")
return self.apply(lambda df: df.dtypes) # type: ignore[return-value]
return self._python_apply_general( # type: ignore[return-value]
lambda df: df.dtypes, self._selected_obj
)

@doc(DataFrame.corrwith.__doc__)
def corrwith(
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,14 @@ def f(self):
return self.plot(*args, **kwargs)

f.__name__ = "plot"
return self._groupby.apply(f)
return self._groupby._python_apply_general(f, self._groupby._selected_obj)

def __getattr__(self, name: str):
def attr(*args, **kwargs):
def f(self):
return getattr(self.plot, name)(*args, **kwargs)

return self._groupby.apply(f)
return self._groupby._python_apply_general(f, self._groupby._selected_obj)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does selected_obj vs obj_with_exclusions matter here? think we're mostly standardizing on the latter

Copy link
Member Author

@rhshadrach rhshadrach Apr 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - this is preserving current behavior that will then be deprecated (#7155). Enforcing that deprecation will allow us to use obj_with_exclusions.


return attr

Expand Down Expand Up @@ -1117,7 +1117,7 @@ def curried(x):
# special case otherwise extra plots are created when catching the
# exception below
if name in base.plotting_methods:
return self.apply(curried)
return self._python_apply_general(curried, self._selected_obj)

is_transform = name in base.transformation_kernels
result = self._python_apply_general(
Expand Down