|
17 | 17 | assert_allclose,
|
18 | 18 | assert_array_equal,
|
19 | 19 | assert_equal,
|
| 20 | + raise_if_dask_computes, |
20 | 21 | requires_bottleneck,
|
21 | 22 | requires_cftime,
|
22 | 23 | requires_dask,
|
@@ -393,37 +394,39 @@ def test_ffill():
|
393 | 394 |
|
394 | 395 | @requires_bottleneck
|
395 | 396 | @requires_dask
|
396 |
| -def test_ffill_dask(): |
| 397 | +@pytest.mark.parametrize("method", ["ffill", "bfill"]) |
| 398 | +def test_ffill_bfill_dask(method): |
397 | 399 | da, _ = make_interpolate_example_data((40, 40), 0.5)
|
398 | 400 | da = da.chunk({"x": 5})
|
399 |
| - actual = da.ffill("time") |
400 |
| - expected = da.load().ffill("time") |
401 |
| - assert isinstance(actual.data, dask_array_type) |
402 |
| - assert_equal(actual, expected) |
403 | 401 |
|
404 |
| - # with limit |
405 |
| - da = da.chunk({"x": 5}) |
406 |
| - actual = da.ffill("time", limit=3) |
407 |
| - expected = da.load().ffill("time", limit=3) |
408 |
| - assert isinstance(actual.data, dask_array_type) |
| 402 | + dask_method = getattr(da, method) |
| 403 | + numpy_method = getattr(da.compute(), method) |
| 404 | + # unchunked axis |
| 405 | + with raise_if_dask_computes(): |
| 406 | + actual = dask_method("time") |
| 407 | + expected = numpy_method("time") |
409 | 408 | assert_equal(actual, expected)
|
410 | 409 |
|
411 |
| - |
412 |
| -@requires_bottleneck |
413 |
| -@requires_dask |
414 |
| -def test_bfill_dask(): |
415 |
| - da, _ = make_interpolate_example_data((40, 40), 0.5) |
416 |
| - da = da.chunk({"x": 5}) |
417 |
| - actual = da.bfill("time") |
418 |
| - expected = da.load().bfill("time") |
419 |
| - assert isinstance(actual.data, dask_array_type) |
| 410 | + # chunked axis |
| 411 | + with raise_if_dask_computes(): |
| 412 | + actual = dask_method("x") |
| 413 | + expected = numpy_method("x") |
420 | 414 | assert_equal(actual, expected)
|
421 | 415 |
|
422 | 416 | # with limit
|
423 |
| - da = da.chunk({"x": 5}) |
424 |
| - actual = da.bfill("time", limit=3) |
425 |
| - expected = da.load().bfill("time", limit=3) |
426 |
| - assert isinstance(actual.data, dask_array_type) |
| 417 | + with raise_if_dask_computes(): |
| 418 | + actual = dask_method("time", limit=3) |
| 419 | + expected = numpy_method("time", limit=3) |
| 420 | + assert_equal(actual, expected) |
| 421 | + |
| 422 | + # limit < axis size |
| 423 | + with pytest.raises(NotImplementedError): |
| 424 | + actual = dask_method("x", limit=2) |
| 425 | + |
| 426 | + # limit > axis size |
| 427 | + with raise_if_dask_computes(): |
| 428 | + actual = dask_method("x", limit=41) |
| 429 | + expected = numpy_method("x", limit=41) |
427 | 430 | assert_equal(actual, expected)
|
428 | 431 |
|
429 | 432 |
|
|
0 commit comments