-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: groupby.agg doesn't include grouping columns in result when selected #51398
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
doc/source/whatsnew/v2.0.0.rst
Outdated
@@ -1362,7 +1362,7 @@ Groupby/resample/rolling | |||
- Bug in :meth:`.DataFrameGroupBy.describe` produced incorrect results when data had duplicate columns (:issue:`50806`) | |||
- Bug in :meth:`.DataFrameGroupBy.agg` with ``engine="numba"`` failing to respect ``as_index=False`` (:issue:`51228`) | |||
- Bug in :meth:`DataFrameGroupBy.agg`, :meth:`SeriesGroupBy.agg`, and :meth:`Resampler.agg` would ignore arguments when passed a list of functions (:issue:`50863`) | |||
- | |||
- Bug in :meth:`DataFrameGroupBy.agg` with multiple groupings would not include groupings in the result when they occurred in the selected columns (:issue:`51186`) |
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.
with multiple groupings
this might not be clear without looking at the new test
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.
Yea, I wasn't sure how to describe that the bug only occurs with .groupby([x, y])
and not .groupby(x)
. Is there better language that could be used here, or maybe just remove it altogether?
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.
'after subsetting columns (e.g. gb[["a", "b"]].agg(...)
'?
Potential follow-up that this makes possible: _iterate_slices is only used in _python_agg_general, where it iterates over columns calling agg_series. agg_series iterates over groups. Instead we could iterate differently over groups, which would look a lot like _aggregate_frame. |
…ate_slices � Conflicts: � doc/source/whatsnew/v2.0.0.rst
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.
LGTM
Assuming no objection, going to merge when greenish. Currently targeted at 2.1. |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.