@@ -345,19 +345,44 @@ def aggregate(self, func=None, *args, **kwargs):
345345 # This is not implemented in pandas,
346346 # so we throw a different message
347347 raise NotImplementedError ("axis other than 0 is not supported" )
348+ if isinstance (func , dict ) or func is None :
349+ if func is None :
350+ func = {}
351+ else :
352+ if any (i not in self ._df .columns for i in func .keys ()):
353+ from pandas .core .base import SpecificationError
348354
349- if func is None or is_list_like (func ):
355+ raise SpecificationError ("nested renamer is not supported" )
356+ if isinstance (self ._by , type (self ._query_compiler )):
357+ by = list (self ._by .columns )
358+ else :
359+ by = self ._by
360+ # We convert to the string version of the function for simplicity.
361+ func_dict = {
362+ k : v if not callable (v ) or v .__name__ not in dir (self ) else v .__name__
363+ for k , v in func .items ()
364+ }
365+ subset_cols = list (func_dict .keys ()) + (
366+ list (self ._by .columns )
367+ if isinstance (self ._by , type (self ._query_compiler ))
368+ and all (c in self ._df .columns for c in self ._by .columns )
369+ else []
370+ )
371+ return type (self ._df )(
372+ query_compiler = self ._df [subset_cols ]._query_compiler .groupby_dict_agg (
373+ by , func_dict , self ._kwargs , kwargs , drop = self ._drop
374+ )
375+ )
376+ if is_list_like (func ):
350377 return self ._default_to_pandas (
351378 lambda df , * args , ** kwargs : df .aggregate (func , * args , ** kwargs ),
352379 * args ,
353380 ** kwargs ,
354381 )
355-
356382 if isinstance (func , str ):
357383 agg_func = getattr (self , func , None )
358384 if callable (agg_func ):
359385 return agg_func (* args , ** kwargs )
360-
361386 return self ._apply_agg_function (
362387 lambda df , * args , ** kwargs : df .aggregate (func , * args , ** kwargs ),
363388 drop = self ._as_index ,
0 commit comments