@@ -108,16 +108,34 @@ def setup(self):
108
108
self .N = 10000
109
109
self .labels = np .random .randint (0 , 2000 , size = self .N )
110
110
self .labels2 = np .random .randint (0 , 3 , size = self .N )
111
- self .df = DataFrame ({'key' : self .labels , 'key2' : self .labels2 , 'value1' : randn (self .N ), 'value2' : (['foo' , 'bar' , 'baz' , 'qux' ] * (self .N / 4 )), })
112
-
113
- def f (self , g ):
111
+ self .df = DataFrame ({
112
+ 'key' : self .labels ,
113
+ 'key2' : self .labels2 ,
114
+ 'value1' : randn (self .N ),
115
+ 'value2' : (['foo' , 'bar' , 'baz' , 'qux' ] * (self .N / 4 )),
116
+ })
117
+
118
+ @staticmethod
119
+ def scalar_function (g ):
114
120
return 1
115
121
116
- def time_groupby_frame_apply (self ):
117
- self .df .groupby (['key' , 'key2' ]).apply (self .f )
122
+ def time_groupby_frame_apply_scalar_function (self ):
123
+ self .df .groupby (['key' , 'key2' ]).apply (self .scalar_function )
124
+
125
+ def time_groupby_frame_apply_scalar_function_overhead (self ):
126
+ self .df .groupby ('key' ).apply (self .scalar_function )
127
+
128
+ @staticmethod
129
+ def df_copy_function (g ):
130
+ # ensure that the group name is available (see GH #15062)
131
+ g .name
132
+ return g .copy ()
133
+
134
+ def time_groupby_frame_df_copy_function (self ):
135
+ self .df .groupby (['key' , 'key2' ]).apply (self .df_copy_function )
118
136
119
- def time_groupby_frame_apply_overhead (self ):
120
- self .df .groupby ('key' ).apply (self .f )
137
+ def time_groupby_frame_apply_df_copy_overhead (self ):
138
+ self .df .groupby ('key' ).apply (self .df_copy_function )
121
139
122
140
123
141
#----------------------------------------------------------------------
0 commit comments