MCPcopy
hub / github.com/pydata/xarray / test_graph_manipulation

Function test_graph_manipulation

xarray/tests/test_dask.py:1793–1822  ·  view source on GitHub ↗

dask.graph_manipulation passes an optional parameter, "rename", to the rebuilder function returned by __dask_postperist__; also, the dsk passed to the rebuilder is a HighLevelGraph whereas with dask.persist() and dask.optimize() it's a plain dict.

()

Source from the content-addressed store, hash-verified

1791
1792
1793def test_graph_manipulation():
1794 """dask.graph_manipulation passes an optional parameter, "rename", to the rebuilder
1795 function returned by __dask_postperist__; also, the dsk passed to the rebuilder is
1796 a HighLevelGraph whereas with dask.persist() and dask.optimize() it's a plain dict.
1797 """
1798 import dask.graph_manipulation as gm
1799
1800 v = Variable(["x"], [1, 2]).chunk(-1).chunk(1) * 2
1801 da = DataArray(v)
1802 ds = Dataset({"d1": v[0], "d2": v[1], "d3": ("x", [3, 4])})
1803
1804 v2, da2, ds2 = gm.clone(v, da, ds)
1805
1806 assert_equal(v2, v)
1807 assert_equal(da2, da)
1808 assert_equal(ds2, ds)
1809
1810 for a, b in ((v, v2), (da, da2), (ds, ds2)):
1811 assert a.__dask_layers__() != b.__dask_layers__()
1812 assert len(a.__dask_layers__()) == len(b.__dask_layers__())
1813 assert a.__dask_graph__().keys() != b.__dask_graph__().keys() # type: ignore[union-attr]
1814 assert len(a.__dask_graph__()) == len(b.__dask_graph__()) # type: ignore[arg-type]
1815 assert a.__dask_graph__().layers.keys() != b.__dask_graph__().layers.keys() # type: ignore[union-attr]
1816 assert len(a.__dask_graph__().layers) == len(b.__dask_graph__().layers) # type: ignore[union-attr]
1817
1818 # Above we performed a slice operation; adding the two slices back together creates
1819 # a diamond-shaped dependency graph, which in turn will trigger a collision in layer
1820 # names if we were to use HighLevelGraph.cull() instead of
1821 # HighLevelGraph.cull_layers() in Dataset.__dask_postpersist__().
1822 assert_equal(ds2.d1 + ds2.d2, ds.d1 + ds.d2)
1823
1824
1825def test_new_index_var_computes_once():

Callers

nothing calls this directly

Calls 8

VariableClass · 0.90
DataArrayClass · 0.90
DatasetClass · 0.90
assert_equalFunction · 0.90
keysMethod · 0.80
chunkMethod · 0.45
__dask_layers__Method · 0.45
__dask_graph__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…