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