@@ -242,15 +242,18 @@ def aggregate(self, func, *args, **kwargs):
242242 # grouper specific aggregations
243243 if self .grouper .nkeys > 1 :
244244 return self ._python_agg_general (func , * args , ** kwargs )
245+ elif args or kwargs :
246+ result = self ._aggregate_generic (func , * args , ** kwargs )
245247 else :
246248
247249 # try to treat as if we are passing a list
248250 try :
249- assert not args and not kwargs
250251 result = self ._aggregate_multiple_funcs (
251252 [func ], _level = _level , _axis = self .axis
252253 )
253-
254+ except Exception :
255+ result = self ._aggregate_generic (func )
256+ else :
254257 result .columns = Index (
255258 result .columns .levels [0 ], name = self ._selected_obj .columns .name
256259 )
@@ -260,8 +263,6 @@ def aggregate(self, func, *args, **kwargs):
260263 # values. concat no longer converts DataFrame[Sparse]
261264 # to SparseDataFrame, so we do it here.
262265 result = SparseDataFrame (result ._data )
263- except Exception :
264- result = self ._aggregate_generic (func , * args , ** kwargs )
265266
266267 if not self .as_index :
267268 self ._insert_inaxis_grouper_inplace (result )
@@ -313,10 +314,10 @@ def _aggregate_item_by_item(self, func, *args, **kwargs):
313314 cannot_agg = []
314315 errors = None
315316 for item in obj :
316- try :
317- data = obj [item ]
318- colg = SeriesGroupBy (data , selection = item , grouper = self .grouper )
317+ data = obj [item ]
318+ colg = SeriesGroupBy (data , selection = item , grouper = self .grouper )
319319
320+ try :
320321 cast = self ._transform_should_cast (func )
321322
322323 result [item ] = colg .aggregate (func , * args , ** kwargs )
@@ -684,7 +685,7 @@ def _transform_item_by_item(self, obj, wrapper):
684685
685686 return DataFrame (output , index = obj .index , columns = columns )
686687
687- def filter (self , func , dropna = True , * args , ** kwargs ): # noqa
688+ def filter (self , func , dropna = True , * args , ** kwargs ):
688689 """
689690 Return a copy of a DataFrame excluding elements from groups that
690691 do not satisfy the boolean criterion specified by func.
0 commit comments