MCPcopy Create free account
hub / github.com/dask/dask / test_shared_tasks

Function test_shared_tasks

dask/array/tests/test_xarray.py:139–166  ·  view source on GitHub ↗
(wrap_xarray)

Source from the content-addressed store, hash-verified

137
138@pytest.mark.parametrize("wrap_xarray", [False, True])
139def 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
169def test_slicing():

Callers

nothing calls this directly

Calls 3

zerosMethod · 0.45
map_blocksMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected