Skip to content

BUG: Value error aggregate item by item #15083

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 4 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 doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Bug Fixes
- Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`)
- Bug in ``pd.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14915`)


- Bug in ``_GroupBy`` where a ``ValueError`` is raised without a message. (:issue:`15082`)


- Bug in ``Series.iloc`` where a ``Categorical`` object for list-like indexes input was returned, where a ``Series`` was expected. (:issue:`14580`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ def curried(x):
try:
return self._aggregate_item_by_item(name,
*args, **kwargs)
except (AttributeError):
raise ValueError
except (AttributeError) as e:
raise ValueError(e)

return wrapper

Expand Down
25 changes: 25 additions & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,31 @@ def max_value(group):
'int64': 1}).sort_values()
assert_series_equal(result, expected)

def test_groupby_aggregate_item_by_item(self):
def test_df():
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be a much simpler construction of a test data frame

s = pd.DataFrame(np.array([[13, 14, 15, 16]]),
index=[0],
columns=['b', 'c', 'd', 'e'])
a1 = [s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 2]
a2 = [s, s, datetime.strptime('2016-12-28', "%Y-%m-%d"), 'asdf', 6]
num = np.array([a1, a2])
columns = ['b', 'c', 'd', 'e', 'f']
idx = [x for x in xrange(0, len(num))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps try changing this line to idx = range(len(num))?

return pd.DataFrame(num, index=idx, columns=columns)
c = [test_df().sort_values(['d', 'e', 'f']),
test_df().sort_values(['d', 'e', 'f'])]
df = pd.concat(c)
df = df[["e", "a"]].copy().reset_index(drop=True)
df["e_idx"] = df["e"]
what = [0, 0.5, 0.5, 1]

def x():
df.groupby(["e_idx", "e"])["a"].quantile(what)
self.assertRaisesRegexp(ValueError,
"'SeriesGroupBy' object "
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not any more useful

"has no attribute '_aggregate_item_by_item'",
x)

def test_groupby_return_type(self):

# GH2893, return a reduced type
Expand Down