Skip to content

Commit 88a4a3d

Browse files
committed
add back the other asv tests
1 parent a89f62b commit 88a4a3d

11 files changed

+1062
-0
lines changed

asv_bench/benchmarks/combine.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
3+
import xarray as xr
4+
5+
6+
class Combine:
7+
"""Benchmark concatenating and merging large datasets"""
8+
9+
def setup(self):
10+
"""Create 4 datasets with two different variables"""
11+
12+
t_size, x_size, y_size = 50, 450, 400
13+
t = np.arange(t_size)
14+
data = np.random.randn(t_size, x_size, y_size)
15+
16+
self.dsA0 = xr.Dataset(
17+
{"A": xr.DataArray(data, coords={"T": t}, dims=("T", "X", "Y"))}
18+
)
19+
self.dsA1 = xr.Dataset(
20+
{"A": xr.DataArray(data, coords={"T": t + t_size}, dims=("T", "X", "Y"))}
21+
)
22+
self.dsB0 = xr.Dataset(
23+
{"B": xr.DataArray(data, coords={"T": t}, dims=("T", "X", "Y"))}
24+
)
25+
self.dsB1 = xr.Dataset(
26+
{"B": xr.DataArray(data, coords={"T": t + t_size}, dims=("T", "X", "Y"))}
27+
)
28+
29+
def time_combine_nested(self):
30+
datasets = [[self.dsA0, self.dsA1], [self.dsB0, self.dsB1]]
31+
32+
xr.combine_nested(datasets, concat_dim=[None, "T"])
33+
34+
def time_combine_by_coords(self):
35+
"""Also has to load and arrange t coordinate"""
36+
datasets = [self.dsA0, self.dsA1, self.dsB0, self.dsB1]
37+
38+
xr.combine_by_coords(datasets)
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import pandas as pd
2+
3+
import xarray as xr
4+
5+
from . import parameterized, randn, requires_dask
6+
7+
8+
def make_bench_data(shape, frac_nan, chunks):
9+
vals = randn(shape, frac_nan)
10+
coords = {"time": pd.date_range("2000-01-01", freq="D", periods=shape[0])}
11+
da = xr.DataArray(vals, dims=("time", "x", "y"), coords=coords)
12+
13+
if chunks is not None:
14+
da = da.chunk(chunks)
15+
16+
return da
17+
18+
19+
def requires_bottleneck():
20+
try:
21+
import bottleneck # noqa: F401
22+
except ImportError:
23+
raise NotImplementedError()
24+
25+
26+
class DataArrayMissingInterpolateNA:
27+
def setup(self, shape, chunks, limit):
28+
if chunks is not None:
29+
requires_dask()
30+
self.da = make_bench_data(shape, 0.1, chunks)
31+
32+
@parameterized(
33+
["shape", "chunks", "limit"],
34+
(
35+
[(365, 75, 75)],
36+
[None, {"x": 25, "y": 25}],
37+
[None, 3],
38+
),
39+
)
40+
def time_interpolate_na(self, shape, chunks, limit):
41+
actual = self.da.interpolate_na(dim="time", method="linear", limit=limit)
42+
43+
if chunks is not None:
44+
actual = actual.compute()
45+
46+
47+
class DataArrayMissingBottleneck:
48+
def setup(self, shape, chunks, limit):
49+
requires_bottleneck()
50+
if chunks is not None:
51+
requires_dask()
52+
self.da = make_bench_data(shape, 0.1, chunks)
53+
54+
@parameterized(
55+
["shape", "chunks", "limit"],
56+
(
57+
[(365, 75, 75)],
58+
[None, {"x": 25, "y": 25}],
59+
[None, 3],
60+
),
61+
)
62+
def time_ffill(self, shape, chunks, limit):
63+
actual = self.da.ffill(dim="time", limit=limit)
64+
65+
if chunks is not None:
66+
actual = actual.compute()
67+
68+
@parameterized(
69+
["shape", "chunks", "limit"],
70+
(
71+
[(365, 75, 75)],
72+
[None, {"x": 25, "y": 25}],
73+
[None, 3],
74+
),
75+
)
76+
def time_bfill(self, shape, chunks, limit):
77+
actual = self.da.ffill(dim="time", limit=limit)
78+
79+
if chunks is not None:
80+
actual = actual.compute()

0 commit comments

Comments
 (0)