Skip to content

Commit 492f1c2

Browse files
committed
PERF: add asv benchmarks for .corr() and .cov()
1 parent a9ee88e commit 492f1c2

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

asv_bench/benchmarks/stat_ops.py

+32-4
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,42 @@ def time_average_old(self, constructor, pct):
9696

9797
class Correlation(object):
9898

99-
params = ['spearman', 'kendall', 'pearson']
100-
param_names = ['method']
99+
params = [['spearman', 'kendall', 'pearson'], [True, False]]
100+
param_names = ['method', 'use_bottleneck']
101101

102-
def setup(self, method):
102+
def setup(self, method, use_bottleneck):
103+
try:
104+
pd.options.compute.use_bottleneck = use_bottleneck
105+
except TypeError:
106+
from pandas.core import nanops
107+
nanops._USE_BOTTLENECK = use_bottleneck
103108
self.df = pd.DataFrame(np.random.randn(1000, 30))
109+
self.s = pd.Series(np.random.randn(1000))
110+
self.s2 = pd.Series(np.random.randn(1000))
104111

105-
def time_corr(self, method):
112+
def time_corr(self, method, use_bottleneck):
106113
self.df.corr(method=method)
107114

115+
def time_corr_series(self, method, use_bottleneck):
116+
self.s.corr(self.s2, method=method)
117+
118+
119+
class Covariance(object):
120+
121+
params = [[True, False]]
122+
param_names = ['use_bottleneck']
123+
124+
def setup(self, use_bottleneck):
125+
try:
126+
pd.options.compute.use_bottleneck = use_bottleneck
127+
except TypeError:
128+
from pandas.core import nanops
129+
nanops._USE_BOTTLENECK = use_bottleneck
130+
self.s = pd.Series(np.random.randn(100000))
131+
self.s2 = pd.Series(np.random.randn(100000))
132+
133+
def time_cov_series(self, use_bottleneck):
134+
self.s.cov(self.s2)
135+
108136

109137
from .pandas_vb_common import setup # noqa: F401

0 commit comments

Comments
 (0)