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

Function test_zarr_sharding_roundtrip

dask/array/tests/test_array_core.py:4971–4997  ·  view source on GitHub ↗

Test sharding with various chunk and shard combinations

(tmp_path, chunks, shards)

Source from the content-addressed store, hash-verified

4969 ],
4970)
4971def test_zarr_sharding_roundtrip(tmp_path, chunks, shards):
4972 """Test sharding with various chunk and shard combinations"""
4973 zarr = pytest.importorskip("zarr", minversion="3.0.0")
4974
4975 a = da.zeros((60, 60), chunks=chunks)
4976 zarr_array_kwargs = {"shards": shards}
4977
4978 a.to_zarr(tmp_path, **zarr_array_kwargs)
4979
4980 store = zarr.storage.FsspecStore.from_url(tmp_path)
4981 z = zarr.open_array(store)
4982
4983 assert z.shards == shards
4984
4985 a2 = da.from_zarr(tmp_path)
4986 assert_eq(a, a2)
4987 assert a2.chunks == a.chunks
4988
4989 b = da.ones((60, 60), chunks=chunks)
4990 with pytest.raises(ValueError, match="Cannot use"):
4991 b.to_zarr(tmp_path, mode="r")
4992
4993 b.to_zarr(tmp_path, mode="w", **zarr_array_kwargs)
4994
4995 b2 = da.from_zarr(tmp_path)
4996 assert_eq(b, b2)
4997 assert b2.chunks == b.chunks
4998
4999
5000def test_zarr_roundtrip_with_path_like():

Callers

nothing calls this directly

Calls 4

assert_eqFunction · 0.90
to_zarrMethod · 0.80
zerosMethod · 0.45
onesMethod · 0.45

Tested by

no test coverage detected