@@ -324,6 +324,9 @@ def agg_list_like(self) -> DataFrame | Series:
324
324
keys = []
325
325
326
326
is_groupby = isinstance (obj , (DataFrameGroupBy , SeriesGroupBy ))
327
+ is_ser_or_df = isinstance (obj , (ABCDataFrame , ABCSeries ))
328
+ this_args = [self .axis , * self .args ] if is_ser_or_df else self .args
329
+
327
330
context_manager : ContextManager
328
331
if is_groupby :
329
332
# When as_index=False, we combine all results using indices
@@ -336,12 +339,7 @@ def agg_list_like(self) -> DataFrame | Series:
336
339
if selected_obj .ndim == 1 :
337
340
for a in arg :
338
341
colg = obj ._gotitem (selected_obj .name , ndim = 1 , subset = selected_obj )
339
- if isinstance (colg , (ABCSeries , ABCDataFrame )):
340
- new_res = colg .aggregate (
341
- a , self .axis , * self .args , ** self .kwargs
342
- )
343
- else :
344
- new_res = colg .aggregate (a , * self .args , ** self .kwargs )
342
+ new_res = colg .aggregate (a , * this_args , ** self .kwargs )
345
343
results .append (new_res )
346
344
347
345
# make sure we find a good name
@@ -352,12 +350,7 @@ def agg_list_like(self) -> DataFrame | Series:
352
350
indices = []
353
351
for index , col in enumerate (selected_obj ):
354
352
colg = obj ._gotitem (col , ndim = 1 , subset = selected_obj .iloc [:, index ])
355
- if isinstance (colg , (ABCSeries , ABCDataFrame )):
356
- new_res = colg .aggregate (
357
- arg , self .axis , * self .args , ** self .kwargs
358
- )
359
- else :
360
- new_res = colg .aggregate (arg , * self .args , ** self .kwargs )
353
+ new_res = colg .aggregate (arg , * this_args , ** self .kwargs )
361
354
results .append (new_res )
362
355
indices .append (index )
363
356
keys = selected_obj .columns .take (indices )
0 commit comments