Skip to content

CLN: raise ValueError instead of Exception #28352

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

Merged
merged 1 commit into from
Sep 9, 2019
Merged
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
8 changes: 6 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ def _aggregate_item_by_item(self, func, *args, **kwargs):
if cast:
result[item] = self._try_cast(result[item], data)

except ValueError:
except ValueError as err:
if "Must produce aggregated value" in str(err):
# raised in _aggregate_named, handle at higher level
# see test_apply_with_mutated_index
raise
cannot_agg.append(item)
continue
except TypeError as e:
Expand Down Expand Up @@ -1009,7 +1013,7 @@ def _aggregate_named(self, func, *args, **kwargs):
group.name = name
output = func(group, *args, **kwargs)
if isinstance(output, (Series, Index, np.ndarray)):
raise Exception("Must produce aggregated value")
raise ValueError("Must produce aggregated value")
result[name] = self._try_cast(output, group)

return result
Expand Down