@@ -363,19 +363,44 @@ def aggregate(self, func=None, *args, **kwargs):
363363 # This is not implemented in pandas,
364364 # so we throw a different message
365365 raise NotImplementedError ("axis other than 0 is not supported" )
366+ if isinstance (func , dict ) or func is None :
367+ if func is None :
368+ func = {}
369+ else :
370+ if any (i not in self ._df .columns for i in func .keys ()):
371+ from pandas .core .base import SpecificationError
366372
367- if func is None or is_list_like (func ):
373+ raise SpecificationError ("nested renamer is not supported" )
374+ if isinstance (self ._by , type (self ._query_compiler )):
375+ by = list (self ._by .columns )
376+ else :
377+ by = self ._by
378+ # We convert to the string version of the function for simplicity.
379+ func_dict = {
380+ k : v if not callable (v ) or v .__name__ not in dir (self ) else v .__name__
381+ for k , v in func .items ()
382+ }
383+ subset_cols = list (func_dict .keys ()) + (
384+ list (self ._by .columns )
385+ if isinstance (self ._by , type (self ._query_compiler ))
386+ and all (c in self ._df .columns for c in self ._by .columns )
387+ else []
388+ )
389+ return type (self ._df )(
390+ query_compiler = self ._df [subset_cols ]._query_compiler .groupby_dict_agg (
391+ by , func_dict , self ._kwargs , kwargs , drop = self ._drop
392+ )
393+ )
394+ if is_list_like (func ):
368395 return self ._default_to_pandas (
369396 lambda df , * args , ** kwargs : df .aggregate (func , * args , ** kwargs ),
370397 * args ,
371398 ** kwargs ,
372399 )
373-
374400 if isinstance (func , str ):
375401 agg_func = getattr (self , func , None )
376402 if callable (agg_func ):
377403 return agg_func (* args , ** kwargs )
378-
379404 return self ._apply_agg_function (
380405 lambda df , * args , ** kwargs : df .aggregate (func , * args , ** kwargs ),
381406 drop = self ._as_index ,
0 commit comments