MCPcopy
hub / github.com/dask/dask / test_xarray_8414

Function test_xarray_8414

dask/tests/test_order.py:2344–2391  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2342
2343
2344def test_xarray_8414():
2345 # https://github.com/pydata/xarray/issues/8414#issuecomment-1793860552
2346 np = pytest.importorskip("numpy")
2347 xr = pytest.importorskip("xarray")
2348
2349 ds = xr.Dataset(
2350 data_vars=dict(
2351 a=(("x", "y"), np.arange(80).reshape(8, 10)),
2352 b=(("y"), np.arange(10)),
2353 )
2354 ).chunk(x=1)
2355
2356 def f(ds):
2357 d = ds.a * ds.b
2358 return (d * ds.b).sum("y")
2359
2360 graph = ds.map_blocks(f).__dask_graph__()
2361
2362 # Two tasks always reduce to one leaf
2363 # plus a commonly shared root node makes three
2364 assert (p := max(diagnostics(graph)[1])) == 3, p
2365
2366 # If the pressure is actually at three, there is not much that could go
2367 # wrong. Still, this asserts that the dependents of the shared dependency
2368 # are only loaded only after the reducers have been computed which given a
2369 # symmetrical graph, means that the steps between the dependents are the
2370 # same. If the xarray implementation changes or fusing enters, the step size
2371 # could grow or shrink but should still be the same everywhere
2372 dsk = dict(graph)
2373 dependencies, dependents = get_deps(dsk)
2374 roots = {k for k, v in dependencies.items() if not v}
2375 shared_roots = {r for r in roots if len(dependents[r]) > 1}
2376 assert len(shared_roots) == 1
2377 shared_root = shared_roots.pop()
2378 o = order(dsk)
2379 assert_topological_sort(dsk, o)
2380
2381 previous = None
2382 step = 0
2383 assert len(dependents[shared_root]) > 2
2384 for dep in sorted(dependents[shared_root], key=o.__getitem__):
2385 if previous is not None:
2386 if step == 0:
2387 step = o[dep] - o[shared_root] - 1
2388 assert step > 1
2389 else:
2390 assert o[dep] == previous + step
2391 previous = o[dep]
2392
2393
2394def test_connecting_to_roots_single_root():

Callers

nothing calls this directly

Calls 12

diagnosticsFunction · 0.90
get_depsFunction · 0.90
orderFunction · 0.90
maxFunction · 0.85
assert_topological_sortFunction · 0.85
reshapeMethod · 0.80
popMethod · 0.80
chunkMethod · 0.45
arangeMethod · 0.45
__dask_graph__Method · 0.45
map_blocksMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…