Skip to content

User facing AssertionError in empty groupby GH5289 #8987

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ def _convert_grouper(axis, grouper):
return grouper.reindex(axis).values
elif isinstance(grouper, (list, Series, Index, np.ndarray)):
if len(grouper) != len(axis):
raise AssertionError('Grouper and axis must be same length')
raise ValueError('Grouper and axis must be same length')
return grouper
else:
return grouper
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -4847,6 +4847,11 @@ def test_groupby_categorical_two_columns(self):
"C3":[nan,nan,nan,nan, 10,100,nan,nan, nan,nan,200,34]}, index=idx)
tm.assert_frame_equal(res, exp)

def test_convert_grouper(axis, grouper):
def f():
len(grouper) != len(axis)
self.assertRaisesRegexp(ValueError, 'Grouper and axis must be same length', f)
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to create a frame and a grouper that actually hits this test. Put a debug statement where the AssertionError is now and run the test suite and see what conditions you need to have it hit their (and if not, then maybe the code is not doing anything)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I'll get around to this soon. Create frame and grouper and then the test - what sort of debug statement did you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just put in a import pdb; pdb.set_trace() right where I want to stop then run the test_groupby.py and see what happens. (this is just to figure things out of course)



def assert_fp_equal(a, b):
assert (np.abs(a - b) < 1e-12).all()
Expand Down