Skip to content

Updating generic.py error message #8618 - New branch #8950

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 1 commit 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
6 changes: 4 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2875,10 +2875,12 @@ def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,
GroupBy object

"""

from pandas.core.groupby import groupby

if level is None and by is None:
raise TypeError("You have to supply one of 'by' and 'level'")
axis = self._get_axis_number(axis)
return groupby(self, by, axis=axis, level=level, as_index=as_index,
return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
sort=sort, group_keys=group_keys, squeeze=squeeze)

def asfreq(self, freq, method=None, how=None, normalize=False):
Expand Down
18 changes: 16 additions & 2 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,9 @@ def test_groupby_level(self):
# raise exception for non-MultiIndex
self.assertRaises(ValueError, self.df.groupby, level=1)




def test_groupby_level_index_names(self):
## GH4014 this used to raise ValueError since 'exp'>1 (in py2)
df = DataFrame({'exp' : ['A']*3 + ['B']*3, 'var1' : lrange(6),}).set_index('exp')
Expand Down Expand Up @@ -1999,6 +2002,17 @@ def test_groupby_level_apply(self):
result = frame['A'].groupby(level=0).count()
self.assertEqual(result.index.name, 'first')

def test_groupby_args(self):
#PR8618 and issue 8015
frame = self.mframe
def j():
frame.groupby()
self.assertRaisesRegexp(TypeError, "You have to supply one of 'by' and 'level'", j)

def k():
frame.groupby(by=None, level=None)
self.assertRaisesRegexp(TypeError, "You have to supply one of 'by' and 'level'", k)

def test_groupby_level_mapper(self):
frame = self.mframe
deleveled = frame.reset_index()
Expand Down Expand Up @@ -3689,8 +3703,8 @@ def test_cumcount(self):
assert_series_equal(expected, sg.cumcount())

def test_cumcount_empty(self):
ge = DataFrame().groupby()
se = Series().groupby()
ge = DataFrame().groupby(level=0)
se = Series().groupby(level=0)
Copy link
Member

Choose a reason for hiding this comment

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

@jreback this test was introduced in #5510, but I think it is ok to change it, as it is mainly testing the empty frame, not the empty groupby call.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree empty just raise (as it is tested above)


e = Series(dtype='int64') # edge case, as this is usually considered float

Expand Down