@@ -430,16 +430,23 @@ def _groupby_and_aggregate(self, how, grouper=None, *args, **kwargs):
430
430
result = grouped ._aggregate_item_by_item (how , * args , ** kwargs )
431
431
else :
432
432
result = grouped .aggregate (how , * args , ** kwargs )
433
- except (DataError , AttributeError , KeyError ):
433
+ except DataError :
434
+ # got TypeErrors on aggregation
435
+ result = grouped .apply (how , * args , ** kwargs )
436
+ except (AttributeError , KeyError ):
434
437
# we have a non-reducing function; try to evaluate
435
438
# alternatively we want to evaluate only a column of the input
439
+
440
+ # test_apply_to_one_column_of_df the function being applied references
441
+ # a DataFrame column, but aggregate_item_by_item operates column-wise
442
+ # on Series, raising AttributeError or KeyError
443
+ # (depending on whether the column lookup uses getattr/__getitem__)
436
444
result = grouped .apply (how , * args , ** kwargs )
445
+
437
446
except ValueError as err :
438
447
if "Must produce aggregated value" in str (err ):
439
448
# raised in _aggregate_named
440
- pass
441
- elif "len(index) != len(labels)" in str (err ):
442
- # raised in libgroupby validation
449
+ # see test_apply_without_aggregation, test_apply_with_mutated_index
443
450
pass
444
451
else :
445
452
raise
0 commit comments