Skip to content

Commit 1715468

Browse files
jbrockmendeljreback
authored andcommitted
CLN: raise early instead of try/except (#29581)
1 parent ab9dca0 commit 1715468

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

pandas/core/groupby/groupby.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -636,24 +636,14 @@ def curried(x):
636636
# TODO: is the above comment accurate?
637637
raise
638638

639-
# related to : GH3688
640-
# try item-by-item
641-
# this can be called recursively, so need to raise
642-
# ValueError
643-
# if we don't have this method to indicated to aggregate to
644-
# mark this column as an error
645-
try:
646-
result = self._aggregate_item_by_item(name, *args, **kwargs)
647-
assert self.obj.ndim == 2
648-
return result
649-
except AttributeError:
650-
# e.g. SparseArray has no flags attr
651-
# FIXME: 'SeriesGroupBy' has no attribute '_aggregate_item_by_item'
652-
# occurs in idxmax() case
653-
# in tests.groupby.test_function.test_non_cython_api
654-
assert self.obj.ndim == 1
639+
if self.obj.ndim == 1:
640+
# this can be called recursively, so need to raise ValueError
655641
raise ValueError
656642

643+
# GH#3688 try to operate item-by-item
644+
result = self._aggregate_item_by_item(name, *args, **kwargs)
645+
return result
646+
657647
wrapper.__name__ = name
658648
return wrapper
659649

0 commit comments

Comments
 (0)