def test_rechunk_method():
    old = ((5, 2, 3),) * 4
    new = ((3, 3, 3, 1),) * 4
    a = np.random.uniform(0, 1, 10000).reshape((10,) * 4)
    x = da.from_array(a, chunks=old)
    x2 = x.rechunk(chunks=new)
    assert x2.chunks == new
    assert np.all(x2.compute() == a)
Test rechunking can be done as a method of dask array.
dataset/ETHPy150Open dask/dask/dask/array/tests/test_rechunk.py/test_rechunk_method