Replies: 3 comments
I would say no, we should not be writing data we cannot read back. I thin kthis is likely at least related to this isseu: #10840 |
|
The chunk mismatch on reopen is expected — xarray reads back zarr chunks, not shards. The shard metadata is preserved in zarr but xarray doesn't map it back to Dask chunks on open. Options that avoid the error without disabling safety: ds = xr.open_zarr(store, chunks=shards) — force chunk alignment on open |
|
For the stated second step, if “add some metadata” means dataset or variable attributes, there is no need to send the lazily opened arrays back through import zarr
root = zarr.open_group(
store,
mode="a",
zarr_format=3,
use_consolidated=False,
)
# xr.Dataset.attrs
root.attrs.update({"title": "example", "history": "metadata added"})
# xr.DataArray.attrs for a stored variable, if needed
root["data"].attrs.update({"units": "1", "long_name": "example data"})A subsequent This is appropriate for user/CF-style attributes only. Structural changes such as dimensions, shapes, chunking, sharding, codecs, coordinates, or encoded dtype are not attribute-only changes and should still go through an aligned data-writing path such as reopening/rechunking with shard-aligned Dask chunks. If consolidated metadata is enabled for another store, it must be refreshed after direct metadata changes; the example store was created with |
Uh oh!
There was an error while loading. Please reload this page.
In an effort to rechunk and shard some datasets i am first rechunking the dataset. Later i want reopen the dataset to add some metadata to the dataset. When doing this i get an error that my chunks would overlap Dask chunks
I am chunking the dataset by setting the encoding as that is the only way i have found to store dataset with shards.
First i set the dataset dask chunks to the size of the shard. Then i am setting the chunks and shards in the zarr encoding and finally i am writing to the zarr store. This works just fine and the store is saved as expected.
Next i try to open the dataset, modify some metadata and write it back, causing the error.
I have created a minimal example illustrating the issue
Running this i get
The issue seems to be that when reading back the dataset, the Dask chunks are aligned with the zarr chunks instead of the Zarr shards.
Is this expected behavior? It seems like reopening the dataset, xarray looses information about the sharding.
All reactions