26
26
"""
27
27
28
28
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 ):
30
46
"""
31
47
Provide the groupby facilities.
32
48
"""
@@ -41,9 +57,9 @@ def __init__(self, obj, *args, **kwargs):
41
57
self ._groupby .grouper .mutated = True
42
58
super ().__init__ (obj , * args , ** kwargs )
43
59
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 )
47
63
48
64
def _apply (
49
65
self , func , name = None , window = None , center = None , check_minp = None , ** kwargs
@@ -53,6 +69,7 @@ def _apply(
53
69
performing the original function call on the grouped object.
54
70
"""
55
71
72
+ # TODO: can we de-duplicate with _dispatch?
56
73
def f (x , name = name , * args ):
57
74
x = self ._shallow_copy (x )
58
75
0 commit comments