Skip to content

Commit 95394d5

Browse files
Use set_options for asv bottleneck tests (#5986)
* Use set_options for bottleneck tests * Use set_options in rolling * Update rolling.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update rolling.py * Update rolling.py * set_options not needed. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b2d7cd8 commit 95394d5

File tree

3 files changed

+57
-45
lines changed

3 files changed

+57
-45
lines changed

asv_bench/asv.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"pandas": [""],
6363
"netcdf4": [""],
6464
"scipy": [""],
65-
"bottleneck": ["", null],
65+
"bottleneck": [""],
6666
"dask": [""],
6767
"distributed": [""],
6868
},

asv_bench/benchmarks/dataarray_missing.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ def make_bench_data(shape, frac_nan, chunks):
1616
return da
1717

1818

19-
def requires_bottleneck():
20-
try:
21-
import bottleneck # noqa: F401
22-
except ImportError:
23-
raise NotImplementedError()
24-
25-
2619
class DataArrayMissingInterpolateNA:
2720
def setup(self, shape, chunks, limit):
2821
if chunks is not None:
@@ -46,7 +39,6 @@ def time_interpolate_na(self, shape, chunks, limit):
4639

4740
class DataArrayMissingBottleneck:
4841
def setup(self, shape, chunks, limit):
49-
requires_bottleneck()
5042
if chunks is not None:
5143
requires_dask()
5244
self.da = make_bench_data(shape, 0.1, chunks)

asv_bench/benchmarks/rolling.py

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,45 @@ def setup(self, *args, **kwargs):
3636
randn_long, dims="x", coords={"x": np.arange(long_nx) * 0.1}
3737
)
3838

39-
@parameterized(["func", "center"], (["mean", "count"], [True, False]))
40-
def time_rolling(self, func, center):
41-
getattr(self.ds.rolling(x=window, center=center), func)().load()
42-
43-
@parameterized(["func", "pandas"], (["mean", "count"], [True, False]))
44-
def time_rolling_long(self, func, pandas):
39+
@parameterized(
40+
["func", "center", "use_bottleneck"],
41+
(["mean", "count"], [True, False], [True, False]),
42+
)
43+
def time_rolling(self, func, center, use_bottleneck):
44+
with xr.set_options(use_bottleneck=use_bottleneck):
45+
getattr(self.ds.rolling(x=window, center=center), func)().load()
46+
47+
@parameterized(
48+
["func", "pandas", "use_bottleneck"],
49+
(["mean", "count"], [True, False], [True, False]),
50+
)
51+
def time_rolling_long(self, func, pandas, use_bottleneck):
4552
if pandas:
4653
se = self.da_long.to_series()
4754
getattr(se.rolling(window=window, min_periods=window), func)()
4855
else:
49-
getattr(self.da_long.rolling(x=window, min_periods=window), func)().load()
50-
51-
@parameterized(["window_", "min_periods"], ([20, 40], [5, 5]))
52-
def time_rolling_np(self, window_, min_periods):
53-
self.ds.rolling(x=window_, center=False, min_periods=min_periods).reduce(
54-
getattr(np, "nansum")
55-
).load()
56-
57-
@parameterized(["center", "stride"], ([True, False], [1, 1]))
58-
def time_rolling_construct(self, center, stride):
59-
self.ds.rolling(x=window, center=center).construct(
60-
"window_dim", stride=stride
61-
).sum(dim="window_dim").load()
56+
with xr.set_options(use_bottleneck=use_bottleneck):
57+
getattr(
58+
self.da_long.rolling(x=window, min_periods=window), func
59+
)().load()
60+
61+
@parameterized(
62+
["window_", "min_periods", "use_bottleneck"], ([20, 40], [5, 5], [True, False])
63+
)
64+
def time_rolling_np(self, window_, min_periods, use_bottleneck):
65+
with xr.set_options(use_bottleneck=use_bottleneck):
66+
self.ds.rolling(x=window_, center=False, min_periods=min_periods).reduce(
67+
getattr(np, "nansum")
68+
).load()
69+
70+
@parameterized(
71+
["center", "stride", "use_bottleneck"], ([True, False], [1, 1], [True, False])
72+
)
73+
def time_rolling_construct(self, center, stride, use_bottleneck):
74+
with xr.set_options(use_bottleneck=use_bottleneck):
75+
self.ds.rolling(x=window, center=center).construct(
76+
"window_dim", stride=stride
77+
).sum(dim="window_dim").load()
6278

6379

6480
class RollingDask(Rolling):
@@ -87,24 +103,28 @@ def setup(self, *args, **kwargs):
87103

88104

89105
class DataArrayRollingMemory(RollingMemory):
90-
@parameterized("func", ["sum", "max", "mean"])
91-
def peakmem_ndrolling_reduce(self, func):
92-
roll = self.ds.var1.rolling(x=10, y=4)
93-
getattr(roll, func)()
106+
@parameterized(["func", "use_bottleneck"], (["sum", "max", "mean"], [True, False]))
107+
def peakmem_ndrolling_reduce(self, func, use_bottleneck):
108+
with xr.set_options(use_bottleneck=use_bottleneck):
109+
roll = self.ds.var1.rolling(x=10, y=4)
110+
getattr(roll, func)()
94111

95-
@parameterized("func", ["sum", "max", "mean"])
96-
def peakmem_1drolling_reduce(self, func):
97-
roll = self.ds.var3.rolling(t=100)
98-
getattr(roll, func)()
112+
@parameterized(["func", "use_bottleneck"], (["sum", "max", "mean"], [True, False]))
113+
def peakmem_1drolling_reduce(self, func, use_bottleneck):
114+
with xr.set_options(use_bottleneck=use_bottleneck):
115+
roll = self.ds.var3.rolling(t=100)
116+
getattr(roll, func)()
99117

100118

101119
class DatasetRollingMemory(RollingMemory):
102-
@parameterized("func", ["sum", "max", "mean"])
103-
def peakmem_ndrolling_reduce(self, func):
104-
roll = self.ds.rolling(x=10, y=4)
105-
getattr(roll, func)()
106-
107-
@parameterized("func", ["sum", "max", "mean"])
108-
def peakmem_1drolling_reduce(self, func):
109-
roll = self.ds.rolling(t=100)
110-
getattr(roll, func)()
120+
@parameterized(["func", "use_bottleneck"], (["sum", "max", "mean"], [True, False]))
121+
def peakmem_ndrolling_reduce(self, func, use_bottleneck):
122+
with xr.set_options(use_bottleneck=use_bottleneck):
123+
roll = self.ds.rolling(x=10, y=4)
124+
getattr(roll, func)()
125+
126+
@parameterized(["func", "use_bottleneck"], (["sum", "max", "mean"], [True, False]))
127+
def peakmem_1drolling_reduce(self, func, use_bottleneck):
128+
with xr.set_options(use_bottleneck=use_bottleneck):
129+
roll = self.ds.rolling(t=100)
130+
getattr(roll, func)()

0 commit comments

Comments
 (0)