Skip to content

Commit 04b38a0

Browse files
authored
Consolidate some numbagg tests (#9211)
Some minor repetiton
1 parent 971d71d commit 04b38a0

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

xarray/tests/test_missing.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -421,46 +421,37 @@ def test_ffill():
421421
assert_equal(actual, expected)
422422

423423

424-
def test_ffill_use_bottleneck_numbagg():
424+
@pytest.mark.parametrize("compute_backend", [None], indirect=True)
425+
@pytest.mark.parametrize("method", ["ffill", "bfill"])
426+
def test_b_ffill_use_bottleneck_numbagg(method, compute_backend):
427+
"""
428+
bfill & ffill fail if both bottleneck and numba are disabled
429+
"""
425430
da = xr.DataArray(np.array([4, 5, np.nan], dtype=np.float64), dims="x")
426-
with xr.set_options(use_bottleneck=False, use_numbagg=False):
427-
with pytest.raises(RuntimeError):
428-
da.ffill("x")
431+
with pytest.raises(RuntimeError):
432+
getattr(da, method)("x")
429433

430434

431435
@requires_dask
432-
def test_ffill_use_bottleneck_dask():
436+
@pytest.mark.parametrize("compute_backend", [None], indirect=True)
437+
@pytest.mark.parametrize("method", ["ffill", "bfill"])
438+
def test_b_ffill_use_bottleneck_dask(method, compute_backend):
439+
"""
440+
ffill fails if both bottleneck and numba are disabled, on dask arrays
441+
"""
433442
da = xr.DataArray(np.array([4, 5, np.nan], dtype=np.float64), dims="x")
434-
da = da.chunk({"x": 1})
435-
with xr.set_options(use_bottleneck=False, use_numbagg=False):
436-
with pytest.raises(RuntimeError):
437-
da.ffill("x")
443+
with pytest.raises(RuntimeError):
444+
getattr(da, method)("x")
438445

439446

440447
@requires_numbagg
441448
@requires_dask
442-
def test_ffill_use_numbagg_dask():
443-
with xr.set_options(use_bottleneck=False):
444-
da = xr.DataArray(np.array([4, 5, np.nan], dtype=np.float64), dims="x")
445-
da = da.chunk(x=-1)
446-
# Succeeds with a single chunk:
447-
_ = da.ffill("x").compute()
448-
449-
450-
def test_bfill_use_bottleneck():
451-
da = xr.DataArray(np.array([4, 5, np.nan], dtype=np.float64), dims="x")
452-
with xr.set_options(use_bottleneck=False, use_numbagg=False):
453-
with pytest.raises(RuntimeError):
454-
da.bfill("x")
455-
456-
457-
@requires_dask
458-
def test_bfill_use_bottleneck_dask():
449+
@pytest.mark.parametrize("compute_backend", ["numbagg"], indirect=True)
450+
def test_ffill_use_numbagg_dask(compute_backend):
459451
da = xr.DataArray(np.array([4, 5, np.nan], dtype=np.float64), dims="x")
460-
da = da.chunk({"x": 1})
461-
with xr.set_options(use_bottleneck=False, use_numbagg=False):
462-
with pytest.raises(RuntimeError):
463-
da.bfill("x")
452+
da = da.chunk(x=-1)
453+
# Succeeds with a single chunk:
454+
_ = da.ffill("x").compute()
464455

465456

466457
@requires_bottleneck

0 commit comments

Comments
 (0)