@@ -395,7 +395,11 @@ def _groupby_and_aggregate(self, how, grouper=None, *args, **kwargs):
395
395
grouped = PanelGroupBy (obj , grouper = grouper , axis = self .axis )
396
396
397
397
try :
398
- result = self ._try_aggregate (grouped , how , * args , ** kwargs )
398
+ if isinstance (obj , ABCDataFrame ) and compat .callable (how ):
399
+ # Check if the function is reducing or not.
400
+ result = grouped ._aggregate_item_by_item (how , * args , ** kwargs )
401
+ else :
402
+ result = grouped .aggregate (how , * args , ** kwargs )
399
403
except Exception :
400
404
401
405
# we have a non-reducing function
@@ -405,24 +409,6 @@ def _groupby_and_aggregate(self, how, grouper=None, *args, **kwargs):
405
409
result = self ._apply_loffset (result )
406
410
return self ._wrap_result (result )
407
411
408
- def _try_aggregate (self , grouped , how , * args , ** kwargs ):
409
- """
410
- Tries to aggregate a 'grouped' object.
411
- When 'how' param is a callable, we aggregate item by item
412
- to check if the function is reducing or not.
413
-
414
- Parameters
415
- ----------
416
- grouped : GroupBy object
417
- how : string / cython mapped function
418
- """
419
- if not compat .callable (how ) or isinstance (grouped , PanelGroupBy ):
420
- return grouped .aggregate (how , * args , ** kwargs )
421
-
422
- # Callables might change the count of columns (GH #15169)
423
- result = grouped ._aggregate_item_by_item (how , * args , ** kwargs )
424
- return result
425
-
426
412
def _apply_loffset (self , result ):
427
413
"""
428
414
if loffset is set, offset the result index
0 commit comments