@@ -242,15 +242,18 @@ def aggregate(self, func, *args, **kwargs):
242
242
# grouper specific aggregations
243
243
if self .grouper .nkeys > 1 :
244
244
return self ._python_agg_general (func , * args , ** kwargs )
245
+ elif args or kwargs :
246
+ result = self ._aggregate_generic (func , * args , ** kwargs )
245
247
else :
246
248
247
249
# try to treat as if we are passing a list
248
250
try :
249
- assert not args and not kwargs
250
251
result = self ._aggregate_multiple_funcs (
251
252
[func ], _level = _level , _axis = self .axis
252
253
)
253
-
254
+ except Exception :
255
+ result = self ._aggregate_generic (func )
256
+ else :
254
257
result .columns = Index (
255
258
result .columns .levels [0 ], name = self ._selected_obj .columns .name
256
259
)
@@ -260,8 +263,6 @@ def aggregate(self, func, *args, **kwargs):
260
263
# values. concat no longer converts DataFrame[Sparse]
261
264
# to SparseDataFrame, so we do it here.
262
265
result = SparseDataFrame (result ._data )
263
- except Exception :
264
- result = self ._aggregate_generic (func , * args , ** kwargs )
265
266
266
267
if not self .as_index :
267
268
self ._insert_inaxis_grouper_inplace (result )
@@ -313,10 +314,10 @@ def _aggregate_item_by_item(self, func, *args, **kwargs):
313
314
cannot_agg = []
314
315
errors = None
315
316
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 )
319
319
320
+ try :
320
321
cast = self ._transform_should_cast (func )
321
322
322
323
result [item ] = colg .aggregate (func , * args , ** kwargs )
@@ -684,7 +685,7 @@ def _transform_item_by_item(self, obj, wrapper):
684
685
685
686
return DataFrame (output , index = obj .index , columns = columns )
686
687
687
- def filter (self , func , dropna = True , * args , ** kwargs ): # noqa
688
+ def filter (self , func , dropna = True , * args , ** kwargs ):
688
689
"""
689
690
Return a copy of a DataFrame excluding elements from groups that
690
691
do not satisfy the boolean criterion specified by func.
0 commit comments