-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Groupby tuples #18249
Groupby tuples #18249
Conversation
pandas/core/groupby.py
Outdated
# when MultiIndex, allow tuple to be a key | ||
if not isinstance(key, (tuple, list)) or \ | ||
(isinstance(key, tuple) and is_axis_multiindex): | ||
if not isinstance(key, list): |
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 you add a nice comment here, explaining
pandas/core/generic.py
Outdated
values are used as-is determine the groups. A str or list of strs | ||
may be passed to group by the columns in ``self`` | ||
values are used as-is determine the groups. A label or list of | ||
labels may be passed to group by the columns in ``self``. |
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.
maybe callout what a tuple does.
1c78988
to
65f6da0
Compare
linting issue |
65f6da0
to
dafc838
Compare
Codecov Report
@@ Coverage Diff @@
## master #18249 +/- ##
=========================================
Coverage ? 91.41%
=========================================
Files ? 164
Lines ? 50090
Branches ? 0
=========================================
Hits ? 45790
Misses ? 4300
Partials ? 0
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18249 +/- ##
=========================================
Coverage ? 91.39%
=========================================
Files ? 164
Lines ? 50095
Branches ? 0
=========================================
Hits ? 45783
Misses ? 4312
Partials ? 0
Continue to review full report at Codecov.
|
Fixed! ping @jreback |
thanks! |
xref pandas-dev#17996 Author: Pietro Battiston <[email protected]> Closes pandas-dev#18249 from toobaz/groupby_tuples and squashes the following commits: dafc838 [Pietro Battiston] DOC: Clarification of groupby(by=) argument e0bdfa7 [Pietro Battiston] TST: Test for tuples in columns, fixes to previous tests 74f91e0 [Pietro Battiston] TST: Fix tests which used tuples to pass multiple keys 201a4fe [Pietro Battiston] BUG: Never interpret a tuple as a list of keys
git diff upstream/master -u -- "*.py" | flake8 --diff
Sorry for having missed #17996, where this could have been discussed, but this said I don't think we should treat specially the case of a
MultiIndex
(see the test I added with tuples as labels): we should just interpret what is not a list as a label, as the docs already state (although with some incoherence, which I tried to address).While I was at it, I fixed a typo which made a test inserted in #17996 trivial.