Skip to content

Commit

Permalink
REF: dont catch ValueError in aggregate_item_by_item (pandas-dev#41211)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and JulianWgs committed Jul 3, 2021
1 parent 7171b76 commit d2da352
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,26 +1207,13 @@ def _aggregate_item_by_item(self, func, *args, **kwargs) -> DataFrame:

obj = self._obj_with_exclusions
result: dict[int | str, NDFrame] = {}
cannot_agg = []
for item in obj:
data = obj[item]
colg = SeriesGroupBy(data, selection=item, grouper=self.grouper)

try:
result[item] = colg.aggregate(func, *args, **kwargs)

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
# otherwise we get here from an AttributeError in _make_wrapper
cannot_agg.append(item)
continue
result[item] = colg.aggregate(func, *args, **kwargs)

result_columns = obj.columns
if cannot_agg:
result_columns = result_columns.drop(cannot_agg)

return self.obj._constructor(result, columns=result_columns)

Expand Down

0 comments on commit d2da352

Please sign in to comment.