Test sharding with various chunk and shard combinations
(tmp_path, chunks, shards)
| 4969 | ], |
| 4970 | ) |
| 4971 | def 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 | |
| 5000 | def test_zarr_roundtrip_with_path_like(): |