Skip to content

BUG: fix ngroups and len(groups) inconsistency when using [Grouper(freq=)] (GH33132) #33135

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

Closed
wants to merge 2 commits into from

Conversation

falcaopetri
Copy link

@falcaopetri falcaopetri changed the title BUG: fix ngroups and len(groups) inconsistency when using [Grouper(freq=)] (GH26326) BUG: fix ngroups and len(groups) inconsistency when using [Grouper(freq=)] (GH33132) Mar 29, 2020
@@ -1863,6 +1863,17 @@ def test_groupby_groups_in_BaseGrouper():
expected = df.groupby(["beta", "alpha"])
assert result.groups == expected.groups

# GH 33132
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this a separate test

result = df.groupby(["beta", pd.Grouper(level="alpha", freq='D')])
assert result.ngroups == len(result)

result = df.groupby([pd.Grouper(level="alpha", freq='D'), "beta"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter is going to want double-quotes on 'D'

@@ -837,11 +838,22 @@ def names(self):

@property
def groupings(self) -> "List[grouper.Grouping]":
codes, _, _ = self.group_info
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure what you are hoping to accomplish here.

]

def __iter__(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue then len(Grouper) != ngroups right? why are you adding __iter__? rather than for example overriding __len__?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed changing __iter__ was a bad idea since this changes the behavior of resample. Anyway, iterating over a nested BinGrouper is somewhat part of the problem (check #33132 (comment) plz). #33303 probably has a better approach to resolve this.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: wrong df.groupby().groups when grouping with [Grouper(freq=), ...]
3 participants