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