@@ -749,8 +749,20 @@ def apply(self, func, *args, **kwargs):
749
749
klass = 'Series' ,
750
750
axis = '' )
751
751
@Appender (_shared_docs ['aggregate' ])
752
- def aggregate (self , func_or_funcs , * args , ** kwargs ):
752
+ def aggregate (self , func_or_funcs = None , * args , ** kwargs ):
753
753
_level = kwargs .pop ('_level' , None )
754
+
755
+ relabeling = func_or_funcs is None
756
+ columns = None
757
+ no_arg_message = ("Must provide 'func_or_funcs' or named "
758
+ "aggregation **kwargs." )
759
+ if relabeling :
760
+ columns = list (kwargs )
761
+ func_or_funcs = list (kwargs .values ())
762
+ kwargs = {}
763
+ if not columns :
764
+ raise TypeError (no_arg_message )
765
+
754
766
if isinstance (func_or_funcs , str ):
755
767
return getattr (self , func_or_funcs )(* args , ** kwargs )
756
768
@@ -759,6 +771,8 @@ def aggregate(self, func_or_funcs, *args, **kwargs):
759
771
# but not the class list / tuple itself.
760
772
ret = self ._aggregate_multiple_funcs (func_or_funcs ,
761
773
(_level or 0 ) + 1 )
774
+ if relabeling :
775
+ ret .columns = columns
762
776
else :
763
777
cyfunc = self ._is_cython_func (func_or_funcs )
764
778
if cyfunc and not args and not kwargs :
@@ -793,11 +807,14 @@ def _aggregate_multiple_funcs(self, arg, _level):
793
807
# have not shown a higher level one
794
808
# GH 15931
795
809
if isinstance (self ._selected_obj , Series ) and _level <= 1 :
796
- warnings .warn (
797
- ("using a dict on a Series for aggregation\n "
798
- "is deprecated and will be removed in a future "
799
- "version" ),
800
- FutureWarning , stacklevel = 3 )
810
+ msg = dedent ("""\
811
+ using a dict on a Series for aggregation
812
+ is deprecated and will be removed in a future version. Use \
813
+ named aggregation instead.
814
+
815
+ >>> grouper.agg(name_1=func_1, name_2=func_2)
816
+ """ )
817
+ warnings .warn (msg , FutureWarning , stacklevel = 3 )
801
818
802
819
columns = list (arg .keys ())
803
820
arg = arg .items ()
@@ -1562,7 +1579,7 @@ def groupby_series(obj, col=None):
1562
1579
1563
1580
def _is_multi_agg_with_relabel (** kwargs ):
1564
1581
"""
1565
- Check whether the kwargs pass to .agg look like multi-agg with relabling .
1582
+ Check whether kwargs passed to .agg look like multi-agg with relabeling .
1566
1583
1567
1584
Parameters
1568
1585
----------
0 commit comments