Test expressions with mixed dask and numpy arrays.
()
| 512 | |
| 513 | @requires_dask |
| 514 | def test_eval_dask_mixed_backends() -> None: |
| 515 | """Test expressions with mixed dask and numpy arrays.""" |
| 516 | from xarray.core.utils import is_duck_dask_array |
| 517 | |
| 518 | ds = Dataset( |
| 519 | { |
| 520 | "dask_var": ("x", np.arange(10.0)), |
| 521 | "numpy_var": ("x", np.linspace(0, 1, 10)), |
| 522 | } |
| 523 | ) |
| 524 | # Only chunk one variable |
| 525 | ds["dask_var"] = ds["dask_var"].chunk({"x": 5}) |
| 526 | |
| 527 | with raise_if_dask_computes(): |
| 528 | result = ds.eval("dask_var + numpy_var") |
| 529 | |
| 530 | # Result should be dask-backed when any input is dask |
| 531 | assert is_duck_dask_array(result.data) |
| 532 | |
| 533 | # Verify correctness |
| 534 | expected = ds["dask_var"] + ds["numpy_var"] |
| 535 | assert_equal(result, expected) |
| 536 | |
| 537 | |
| 538 | @requires_dask |
nothing calls this directly
no test coverage detected
searching dependent graphs…