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.
()
| 1791 | |
| 1792 | |
| 1793 | def 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 | |
| 1825 | def test_new_index_var_computes_once(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…