-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Bug: groupby multiindex levels equals rows #16859
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
Changes from 8 commits
7928960
acd449f
d5ec754
f34b10a
cd35777
9404a00
7980d79
2c48282
9af8a47
50c7979
a98db9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,6 +296,7 @@ Groupby/Resample/Rolling | |
- Bug in :func:`infer_freq` causing indices with 2-day gaps during the working week to be wrongly inferred as business daily (:issue:`16624`) | ||
- Bug in ``.rolling(...).quantile()`` which incorrectly used different defaults than :func:`Series.quantile()` and :func:`DataFrame.quantile()` (:issue:`9413`, :issue:`16211`) | ||
- Bug in ``groupby.transform()`` that would coerce boolean dtypes back to float (:issue:`16875`) | ||
- Bug in ``DataFrame.groupby`` when called with index or index + column key numbers equal to the axis length of the groupby (:issue:`16859`) | ||
|
||
Sparse | ||
^^^^^^ | ||
|
@@ -326,4 +327,4 @@ Categorical | |
Other | ||
^^^^^ | ||
- Bug in :func:`eval` where the ``inplace`` parameter was being incorrectly handled (:issue:`16732`) | ||
- Bug in ``.isin()`` in which checking membership in empty ``Series`` objects raised an error (:issue:`16991`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what changed on this line? |
||
- Bug in ``.isin()`` in which checking membership in empty ``Series`` objects raised an error (:issue:`16991`) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3891,6 +3891,19 @@ def predictions(tool): | |
result = df2.groupby('Key').apply(predictions).p1 | ||
tm.assert_series_equal(expected, result) | ||
|
||
def test_gb_key_len_equal_axis_len(self): | ||
# GH16843 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a 1-liner about what this is testing |
||
# test ensures that index and column keys are recognized correctly | ||
# when number of keys equals axis length of groupby | ||
df = pd.DataFrame([['foo', 'bar', 'B', 1], | ||
['foo', 'bar', 'B', 2], | ||
['foo', 'baz', 'C', 3]], | ||
columns=['first', 'second', 'third', 'one']) | ||
df.set_index(['first', 'second'], inplace=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you change to
more idiomatic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, don't pass in |
||
df = df.groupby(['first', 'second', 'third']).size() | ||
assert df.loc[('foo', 'bar', 'B')] == 2 | ||
assert df.loc[('foo', 'baz', 'C')] == 1 | ||
|
||
|
||
def _check_groupby(df, result, keys, field, f=lambda x: x.sum()): | ||
tups = lmap(tuple, df[keys].values) | ||
|
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.
Your description underneath your test I think is clearer about the bug than this description is. Try incorporating some of your test description into here.