Skip to content

Commit 7e75635

Browse files
author
Joe Jevnik
committed
DEV: add groupby asv benchmark
1 parent 710528a commit 7e75635

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

asv_bench/benchmarks/groupby.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,34 @@ def setup(self):
108108
self.N = 10000
109109
self.labels = np.random.randint(0, 2000, size=self.N)
110110
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):
114120
return 1
115121

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)
118136

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)
121139

122140

123141
#----------------------------------------------------------------------

0 commit comments

Comments
 (0)