-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC/CLN: move NDFrame.groupby to (DataFrame|Series).groupby #30314
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
f64fe81
to
fdf3e8c
Compare
Makes sense. Can we get rid of the |
get_groupby is used in |
51868aa
to
0d866ce
Compare
pandas/core/reshape/merge.py
Outdated
@@ -113,6 +114,7 @@ def _groupby_and_merge( | |||
by = [by] | |||
|
|||
lby = left.groupby(by, sort=False) | |||
rby = None # type: Optional[groupby.DataFrameGroupBy] |
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.
This is needed to silence mypy.
0d866ce
to
af073c1
Compare
pandas/core/frame.py
Outdated
group_keys: bool = True, | ||
squeeze: bool = False, | ||
observed: bool = False, | ||
) -> "grp_generic.DataFrameGroupBy": |
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.
Could you do from pandas.core.groupby.generic import DataFrameGroupBy
? That would make the signature a bit cleaner for end users ("grp_generic" is meaningless for them)
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.
That's not possible, because it would give circular import errors.
Maybe in the future, when we we're om min python 3.8, we can do from __future__ import annotations
and get it to work, but that's a long way in the future.
EDIT: I've renamed "grp_generic" to "groupby_generic", which is a bit clearer.
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.
Also not if you put it behind a if TYPE_CHECKING:
?
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.
I actually also don't understand this aspect of importing: what's the difference between from pandas.core.groupby import generic
vs from pandas.core.groupby.generic import DataFrameGroupBy
? Both import the pandas.core.groupby.generic
(and thus run all imports in that file), no?
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.
I'm not sure I can articulate it, but I understand it like this: If you attach a name to the new module (like you'd do in from pandas.core.groupby.generic import DataFrameGroupBy
) you force the pandas.core.groupby.generic
module to be run at import time. This causes an error, if the calling module (here frame.py
) itself must be run before groupby.generic
, casing a circular error.
By not importing a name (here DataFrameGroupby
), running the module is delayed, and things work.
@topper-123 IIUC the grouped = get_groupby(subset, by=None, grouper=grouper, axis=self.axis) To subset.groupby(by=None, grouper=grouper, axis=self.axis) ? I think would be good to go all the way on that cleanup if so |
@WillAyd , good observation, I've removed I've also renamed |
@WillAyd , looking more into it, that doesn't work after all, because the signatures to I'll revert the removal of |
1a3f76f
to
59ef571
Compare
Is this ok to merge? Notice that |
59ef571
to
3266547
Compare
Hmm so I think would be nice if we replaced |
ok with aligning signatures but in a dedicated PR |
ce3dc84
to
138185e
Compare
138185e
to
9ada87c
Compare
I've rebased the PR. I'm not sure I understand how the signatures can be aligned: e.g. |
yeah I am now confused on what was said about aligning things. The Grouper and GroupBy are different things here. thanks for the PR. |
By moving this method up to dataFrame/Series, we get better doc strings and more precise type hints.