Skip to content

ENH: Experimental Higher Order Methods API #45557

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

Closed
wants to merge 11 commits into from

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented Jan 22, 2022

Start of #41112, second attempt at #43736.

  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them

Built docs can be viewed in #43736 (wording slightly changed from there, but results are the same). If we go forward with this approach, needs to run on the CI with failures allowed.

cc @jbrockmendel

@rhshadrach rhshadrach added Enhancement Apply Apply, Aggregate, Transform, Map labels Jan 22, 2022
@jbrockmendel
Copy link
Member

Might wait until Monday to take a look. Troubleshooting azure left me cranky.

@rhshadrach
Copy link
Member Author

@jreback @jbrockmendel friendly ping.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

really just a minor comment.

result = getattr(self.obj, method)(a)
except (TypeError, DataError):
warnings.warn(
f"{name} did not aggregate successfully. If any error is "
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we want to warn here? (e.g. new api can we just raise)

Copy link
Member Author

Choose a reason for hiding this comment

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

Right - new API will just raise. Starting out, I'd like to maintain as much consistency between api.use_hom=True and api.use_hom=False as possible, only making changes that would be hard/impossible to properly deprecate. Since this is already deprecated and will be changed in 2.0, I don't see a need to do it here.


pandas is experimenting with improving the behavior of higher order methods (HOMs). These
are methods that take a function as an argument, often a user-defined function (UDF).
They include ``.apply``, ``.agg``, ``.transform``, and ``.filter``. The goal is to make
Copy link
Contributor

Choose a reason for hiding this comment

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

certainly could be done in followups

  • link to the doc-strings for these methods
  • in the doc-strings show the behavior changes when use_hom is enabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will link to doc strings here; going to hold off modifying the public doc-strings until this is ready.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I only listed methods that are currently being modified when using api.use_hom=True. Will expand the list as modifications occur.


if not self.as_index:
self._insert_inaxis_grouper_inplace(result)
result.index = Index(range(len(result)))
Copy link
Member

Choose a reason for hiding this comment

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

some of this looks familiar. is it as de-duplicated as it can reasonably get?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps not, but will be changed when implementing "agg always aggs" (#35725). In other words, duplicating further will likely have to be undone in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants