@@ -324,6 +324,9 @@ def agg_list_like(self) -> DataFrame | Series:
324324 keys = []
325325
326326 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+
327330 context_manager : ContextManager
328331 if is_groupby :
329332 # When as_index=False, we combine all results using indices
@@ -336,12 +339,7 @@ def agg_list_like(self) -> DataFrame | Series:
336339 if selected_obj .ndim == 1 :
337340 for a in arg :
338341 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 )
345343 results .append (new_res )
346344
347345 # make sure we find a good name
@@ -352,12 +350,7 @@ def agg_list_like(self) -> DataFrame | Series:
352350 indices = []
353351 for index , col in enumerate (selected_obj ):
354352 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 )
361354 results .append (new_res )
362355 indices .append (index )
363356 keys = selected_obj .columns .take (indices )
0 commit comments