def _aggregate(self, arg, *args, **kwargs):
is_aggregator = lambda x: isinstance(x, (list, tuple, dict))<EOL>is_nested_renamer = False<EOL>_axis = kwargs.pop('<STR_LIT>', None)<EOL>if _axis is None:<EOL><INDENT>_axis = getattr(self, '<STR_LIT>', <NUM_LIT:0>)<EOL><DEDENT>_level = kwargs.pop('<STR_LIT>', None)<EOL>if isinstance(arg, str):<EOL><INDENT>return self._try_aggregate_string_function(arg, *args,<EOL>**kwargs), None<EOL><DEDENT>if isinstance(arg, dict):<EOL><INDENT>if _axis != <NUM_LIT:0>:  <EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>obj = self._selected_obj<EOL>def nested_renaming_depr(level=<NUM_LIT:4>):<EOL><INDENT>warnings.warn(<EOL>("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT:version>"),<EOL>FutureWarning, stacklevel=level)<EOL><DEDENT>if any(is_aggregator(x) for x in arg.values()):<EOL><INDENT>new_arg = OrderedDict()<EOL>for k, v in arg.items():<EOL><INDENT>if not isinstance(v, (tuple, list, dict)):<EOL><INDENT>new_arg[k] = [v]<EOL><DEDENT>else:<EOL><INDENT>new_arg[k] = v<EOL><DEDENT>if isinstance(v, dict):<EOL><INDENT>is_nested_renamer = True<EOL>if k not in obj.columns:<EOL><INDENT>msg = ('<STR_LIT>'<EOL>'<STR_LIT>').format(key=k)<EOL>raise SpecificationError(msg)<EOL><DEDENT>nested_renaming_depr(<NUM_LIT:4> + (_level or <NUM_LIT:0>))<EOL><DEDENT>elif isinstance(obj, ABCSeries):<EOL><INDENT>nested_renaming_depr()<EOL><DEDENT>elif (isinstance(obj, ABCDataFrame) and<EOL>k not in obj.columns):<EOL><INDENT>raise KeyError(<EOL>"<STR_LIT>".format(col=k))<EOL><DEDENT><DEDENT>arg = new_arg<EOL><DEDENT>else:<EOL><INDENT>keys = list(arg.keys())<EOL>if (isinstance(obj, ABCDataFrame) and<EOL>len(obj.columns.intersection(keys)) != len(keys)):<EOL><INDENT>nested_renaming_depr()<EOL><DEDENT><DEDENT>from pandas.core.reshape.concat import concat<EOL>def _agg_1dim(name, how, subset=None):<EOL><INDENT>"""<STR_LIT>"""<EOL>colg = self._gotitem(name, ndim=<NUM_LIT:1>, subset=subset)<EOL>if colg.ndim != <NUM_LIT:1>:<EOL><INDENT>raise SpecificationError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return colg.aggregate(how, _level=(_level or <NUM_LIT:0>) + <NUM_LIT:1>)<EOL><DEDENT>def _agg_2dim(name, how):<EOL><INDENT>"""<STR_LIT>"""<EOL>colg = self._gotitem(self._selection, ndim=<NUM_LIT:2>,<EOL>subset=obj)<EOL>return colg.aggregate(how, _level=None)<EOL><DEDENT>def _agg(arg, func):<EOL><INDENT>"""<STR_LIT>"""<EOL>result = OrderedDict()<EOL>for fname, agg_how in arg.items():<EOL><INDENT>result[fname] = func(fname, agg_how)<EOL><DEDENT>return result<EOL><DEDENT>keys = list(arg.keys())<EOL>result = OrderedDict()<EOL>if is_nested_renamer:<EOL><INDENT>result = list(_agg(arg, _agg_1dim).values())<EOL>if all(isinstance(r, dict) for r in result):<EOL><INDENT>result, results = OrderedDict(), result<EOL>for r in results:<EOL><INDENT>result.update(r)<EOL><DEDENT>keys = list(result.keys())<EOL><DEDENT>else:<EOL><INDENT>if self._selection is not None:<EOL><INDENT>keys = None<EOL><DEDENT><DEDENT><DEDENT>elif self._selection is not None:<EOL><INDENT>sl = set(self._selection_list)<EOL>if len(sl) == <NUM_LIT:1>:<EOL><INDENT>result = _agg(arg, lambda fname,<EOL>agg_how: _agg_1dim(self._selection, agg_how))<EOL><DEDENT>elif not len(sl - set(keys)):<EOL><INDENT>result = _agg(arg, _agg_1dim)<EOL><DEDENT>else:<EOL><INDENT>result = _agg(arg, _agg_2dim)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>result = _agg(arg, _agg_1dim)<EOL><DEDENT>except SpecificationError:<EOL><INDENT>result = _agg(arg, _agg_2dim)<EOL><DEDENT><DEDENT>def is_any_series():<EOL><INDENT>return any(isinstance(r, ABCSeries) for r in result.values())<EOL><DEDENT>def is_any_frame():<EOL><INDENT>return any(isinstance(r, ABCDataFrame)<EOL>for r in result.values())<EOL><DEDENT>if isinstance(result, list):<EOL><INDENT>return concat(result, keys=keys, axis=<NUM_LIT:1>, sort=True), True<EOL><DEDENT>elif is_any_frame():<EOL><INDENT>return concat([result[k] for k in keys],<EOL>keys=keys, axis=<NUM_LIT:1>), True<EOL><DEDENT>elif isinstance(self, ABCSeries) and is_any_series():<EOL><INDENT>try:<EOL><INDENT>result = concat(result)<EOL><DEDENT>except TypeError:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return result, True<EOL><DEDENT>from pandas import DataFrame, Series<EOL>try:<EOL><INDENT>result = DataFrame(result)<EOL><DEDENT>except ValueError:<EOL><INDENT>result = Series(result,<EOL>name=getattr(self, '<STR_LIT:name>', None))<EOL><DEDENT>return result, True<EOL><DEDENT>elif is_list_like(arg):<EOL><INDENT>return self._aggregate_multiple_funcs(arg,<EOL>_level=_level,<EOL>_axis=_axis), None<EOL><DEDENT>else:<EOL><INDENT>result = None<EOL><DEDENT>f = self._is_cython_func(arg)<EOL>if f and not args and not kwargs:<EOL><INDENT>return getattr(self, f)(), None<EOL><DEDENT>return result, True<EOL>
provide an implementation for the aggregators

Parameters
----------
arg : string, dict, function
*args : args to pass on to the function
**kwargs : kwargs to pass on to the function

Returns
-------
tuple of result, how

Notes
-----
how can be a string describe the required post-processing, or
None if not required