-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: ngroups and len(groups) do not equal when grouping with a list of Grouper and column label (GH26326) #26374
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 1 commit
47a1057
cad3d6b
0dba40d
bb3f6de
dc76a2d
648ddfa
3aaa15c
f8a3220
ca6eff6
c3d5de2
f8f3d8f
b8e4b34
bfdea4c
49615db
050fb89
bf48c41
af63e6e
fe0405a
ee4dffe
ea023de
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 |
---|---|---|
|
@@ -258,7 +258,10 @@ def groups(self): | |
if len(self.groupings) == 1: | ||
return self.groupings[0].groups | ||
else: | ||
to_groupby = zip(*(ping.grouper for ping in self.groupings)) | ||
to_groupby = zip(*(ping.grouper if not isinstance(ping.grouper, | ||
self.__class__) | ||
else ping.grouper.groupings[0].grouper for ping | ||
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. Wouldn't this only work if the grouper was the first item? Would need something more generalizable 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. I was wondering the same. Can Groupers be nested to more than one level? 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. I think this would fail if your test was 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. The problem is with the construction of the |
||
in self.groupings)) | ||
shantanu-gontia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
to_groupby = Index(to_groupby) | ||
return self.axis.groupby(to_groupby) | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1737,3 +1737,15 @@ def test_groupby_multiindex_series_keys_len_equal_group_axis(): | |||||
expected = pd.Series([3], index=ei) | ||||||
|
||||||
assert_series_equal(result, expected) | ||||||
|
||||||
|
||||||
def test_groupby_groups_in_BaseGrouper(): | ||||||
# https://github.com/pandas-dev/pandas/issues/26326 | ||||||
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.
Suggested change
|
||||||
m_index = pd.MultiIndex.from_product([['A', 'B'], | ||||||
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. Use |
||||||
['C', 'D']], names=['alpha', 'beta']) | ||||||
df_sample = pd.DataFrame({'foo': [1, 2, 1, 2], 'bar': [1, 2, 3, 4]}, | ||||||
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.
|
||||||
index=m_index) | ||||||
dfGBY_BaseGrouper = df_sample.groupby([pd.Grouper(level='alpha'), 'beta']) | ||||||
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. Maybe just |
||||||
dfGBY_noBaseGrouper = df_sample.groupby(['alpha', 'beta']) | ||||||
|
||||||
assert(dfGBY_BaseGrouper.groups == dfGBY_noBaseGrouper.groups) | ||||||
shantanu-gontia marked this conversation as resolved.
Show resolved
Hide resolved
|
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 construct a message that is more user facing? These items aren't part of the 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.
User facing as in more user friendly?