-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Groupby agg support multiple funcs numba #53486
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
Conversation
if is_groupby: | ||
engine = self.kwargs.get("engine", None) | ||
engine_kwargs = self.kwargs.get("engine_kwargs", None) | ||
kwargs = {"engine": engine, "engine_kwargs": engine_kwargs} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the method signatures with by adding engine
and engine_kwargs
params instead of mangling kwargs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obj
here can be a Series/DF/Resampler/ too, since the code is shared with there, so it wouldn't be possible to add engine
/engine_kwargs
there (unless we supported numba there too), since agg
there is part of the public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obj
here can be a Series/DF/Resampler/ too, since the code is shared with there, so it wouldn't be possible to add engine
/engine_kwargs
there (unless we supported numba there too), since agg
there is part of the public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more we evolve groupby, the more I realize trying to share this code between Series/DataFrame and groupby was a mistake of mine. I've been thinking we should refactor and separate off groupby entirely (but it can still live in core.apply
). I'm okay with having a bit of a kludge here and will separate/cleanup after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment in the OP ("so I've left that out of this PR") is out dated now, right? I didn't see the commented out test; it's been changed to an xfail. Got it.
if is_groupby: | ||
engine = self.kwargs.get("engine", None) | ||
engine_kwargs = self.kwargs.get("engine_kwargs", None) | ||
kwargs = {"engine": engine, "engine_kwargs": engine_kwargs} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more we evolve groupby, the more I realize trying to share this code between Series/DataFrame and groupby was a mistake of mine. I've been thinking we should refactor and separate off groupby entirely (but it can still live in core.apply
). I'm okay with having a bit of a kludge here and will separate/cleanup after.
@@ -1416,6 +1424,17 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs) | |||
result.columns = columns # type: ignore[assignment] | |||
|
|||
if result is None: | |||
# Remove the kwargs we inserted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we need to go through result = op.agg()
first instead of just using self._aggregate_with_numba
in the if if maybe_use_numba(engine)
branch above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that checks for str/list/dict aggregations, and call back into the agg function itself.
It'll return None, if a callable is passed, though (what this block handles).
Looks pretty good. Just a merge conflict |
Thanks @lithomas1 |
* ENH: Groupby agg support multiple funcs numba * address code review * remove old TODO
* ENH: Groupby agg support multiple funcs numba * address code review * remove old TODO
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Only thing missing for now is Groupby.agg with multiple UDFs. This'll require changes to the shared apply code, so I've left that out of this PR.
(I've added a commented out example test case to address this).