Skip to content

CLN: raise early instead of try/except #29581

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
Nov 12, 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
22 changes: 6 additions & 16 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,24 +636,14 @@ def curried(x):
# TODO: is the above comment accurate?
raise

# related to : GH3688
# try item-by-item
# this can be called recursively, so need to raise
# ValueError
# if we don't have this method to indicated to aggregate to
# mark this column as an error
try:
result = self._aggregate_item_by_item(name, *args, **kwargs)
assert self.obj.ndim == 2
return result
except AttributeError:
# e.g. SparseArray has no flags attr
# FIXME: 'SeriesGroupBy' has no attribute '_aggregate_item_by_item'
# occurs in idxmax() case
# in tests.groupby.test_function.test_non_cython_api
assert self.obj.ndim == 1
if self.obj.ndim == 1:
# this can be called recursively, so need to raise ValueError
raise ValueError

# GH#3688 try to operate item-by-item
result = self._aggregate_item_by_item(name, *args, **kwargs)
return result

wrapper.__name__ = name
return wrapper

Expand Down