diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 4b85da1b7b224..774d9f651bae0 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -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 diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index bf24eda60b986..ef516be28431e 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -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) + def assert_fp_equal(a, b): assert (np.abs(a - b) < 1e-12).all()