2626"""
2727
2828
29- class _GroupByMixin (GroupByMixin ):
29+ def _dispatch (name : str , * args , ** kwargs ):
30+ """
31+ Dispatch to apply.
32+ """
33+
34+ def outer (self , * args , ** kwargs ):
35+ def f (x ):
36+ x = self ._shallow_copy (x , groupby = self ._groupby )
37+ return getattr (x , name )(* args , ** kwargs )
38+
39+ return self ._groupby .apply (f )
40+
41+ outer .__name__ = name
42+ return outer
43+
44+
45+ class WindowGroupByMixin (GroupByMixin ):
3046 """
3147 Provide the groupby facilities.
3248 """
@@ -41,9 +57,9 @@ def __init__(self, obj, *args, **kwargs):
4157 self ._groupby .grouper .mutated = True
4258 super ().__init__ (obj , * args , ** kwargs )
4359
44- count = GroupByMixin . _dispatch ("count" )
45- corr = GroupByMixin . _dispatch ("corr" , other = None , pairwise = None )
46- cov = GroupByMixin . _dispatch ("cov" , other = None , pairwise = None )
60+ count = _dispatch ("count" )
61+ corr = _dispatch ("corr" , other = None , pairwise = None )
62+ cov = _dispatch ("cov" , other = None , pairwise = None )
4763
4864 def _apply (
4965 self , func , name = None , window = None , center = None , check_minp = None , ** kwargs
@@ -53,6 +69,7 @@ def _apply(
5369 performing the original function call on the grouped object.
5470 """
5571
72+ # TODO: can we de-duplicate with _dispatch?
5673 def f (x , name = name , * args ):
5774 x = self ._shallow_copy (x )
5875
0 commit comments