(wrap_xarray)
| 137 | |
| 138 | @pytest.mark.parametrize("wrap_xarray", [False, True]) |
| 139 | def test_shared_tasks(wrap_xarray): |
| 140 | lock = threading.Lock() |
| 141 | total_calls = 0 |
| 142 | |
| 143 | def my_func(a: np.ndarray) -> np.ndarray: |
| 144 | nonlocal total_calls |
| 145 | with lock: |
| 146 | total_calls += 1 |
| 147 | return a |
| 148 | |
| 149 | in1 = da.zeros((5, 5), chunks=2) |
| 150 | res = da.map_blocks( |
| 151 | my_func, in1, meta=np.array((), dtype=in1.dtype), dtype=in1.dtype |
| 152 | ) |
| 153 | out1 = res + 1 |
| 154 | out2 = res + 2 |
| 155 | if wrap_xarray: |
| 156 | out1 = xr.DataArray(out1) |
| 157 | out2 = xr.DataArray(out2) |
| 158 | |
| 159 | comp_res = dask.compute(out1, out2) |
| 160 | |
| 161 | if wrap_xarray: |
| 162 | assert isinstance(comp_res[0], xr.DataArray) |
| 163 | assert isinstance(comp_res[0].data, np.ndarray) |
| 164 | else: |
| 165 | assert isinstance(comp_res[0], np.ndarray) |
| 166 | assert total_calls == in1.blocks.size |
| 167 | |
| 168 | |
| 169 | def test_slicing(): |
nothing calls this directly
no test coverage detected