You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the docstring says "The number of chunks in the stored representation of this array." For v3 data with sharding, the number of stored objects is not the same as the number of chunks.
nchunks_initialized has the same problem -- these properties come from a time before there was a difference between the number of chunks and the number of files stored on disk. that means we kind of need to pick one of the two meanings for these properties. for nchunks_initialized I think it's clear that the intent is to report the number of objects on disk supporting the array. I'm extending that logic to nchunks.
A bit of a curveball, but what if .chunks / .nchunks instead consistently mapped to the on-disk chunk shape, irrespective of the presence of the sharding codec? This is how it was in the zarr-python 3.0.0 betas.
At the moment, reading/writing "chunk-by-chunk" with a sharded array is a bit of a footgun. And workarounds like this are necessary:
Introduce a new .subchunks concept instead? Perhaps a good time to change this is when you start supporting non-regular chunk grids, because .chunks will break anyway.
@LDeakin have a look at #3299, I go all-in on distinguishing shards (on-disk chunk shape) from chunks (unit of concurrent reading). If I understand you correctly, this would remove these footguns
A bit of a curveball, but what if .chunks / .nchunks instead consistently mapped to the on-disk chunk shape, irrespective of the presence of the sharding codec?
can you explain what you mean by "on-disk chunk shape" here?
there are two complications with the idea of making the top-level Array attributes which refer to "chunks" to express the in-metadata chunks / chunk_grid.chunk_shape attributes:
When reading data, people expect that the chunks attribute conveys the unit of parallelism for that operation. With sharding, this is no longer true.
We are already distinguishing between shards and chunks in our array creation API. chunks specifies the unit of read parallelism, and shards, if specified, turns on sharding and allows separate control over the unit of write parallelism. So if you specify chunks alone, it controls the chunks / chunk_grid.chunk_shape attributes, but if you specify chunks and shards together, the chunks controls the chunk_shape attribute of the sharding codec config, and shards controls the chunks / chunk_grid.chunk_shape attributes. IMO we should try to be consistent with this terminology, which argues for normalizing "shards" as the in-memory name for the chunks / chunk_grid.chunk_shape attributes.
Activity
dstansby commentedon Jul 25, 2025
At the moment it reports the number of chunks in the shards:
which seems to make sense to me? What's the situation/reasoning for it to report the number of shards instead?
d-v-b commentedon Jul 25, 2025
the docstring says "The number of chunks in the stored representation of this array." For v3 data with sharding, the number of stored objects is not the same as the number of chunks.
d-v-b commentedon Jul 25, 2025
nchunks_initializedhas the same problem -- these properties come from a time before there was a difference between the number of chunks and the number of files stored on disk. that means we kind of need to pick one of the two meanings for these properties. fornchunks_initializedI think it's clear that the intent is to report the number of objects on disk supporting the array. I'm extending that logic tonchunks.LDeakin commentedon Jul 25, 2025
A bit of a curveball, but what if
.chunks/.nchunksinstead consistently mapped to the on-disk chunk shape, irrespective of the presence of the sharding codec? This is how it was in thezarr-python3.0.0 betas.At the moment, reading/writing "chunk-by-chunk" with a sharded array is a bit of a footgun. And workarounds like this are necessary:
Introduce a new
.subchunksconcept instead? Perhaps a good time to change this is when you start supporting non-regular chunk grids, because.chunkswill break anyway.d-v-b commentedon Jul 26, 2025
@LDeakin have a look at #3299, I go all-in on distinguishing shards (on-disk chunk shape) from chunks (unit of concurrent reading). If I understand you correctly, this would remove these footguns
d-v-b commentedon Jul 27, 2025
can you explain what you mean by "on-disk chunk shape" here?
LDeakin commentedon Jul 27, 2025
The chunk shape defined by the chunk grid.
d-v-b commentedon Jul 27, 2025
there are two complications with the idea of making the top-level
Arrayattributes which refer to"chunks"to express the in-metadatachunks/chunk_grid.chunk_shapeattributes:chunksattribute conveys the unit of parallelism for that operation. With sharding, this is no longer true.shardsandchunksin our array creation API.chunksspecifies the unit of read parallelism, andshards, if specified, turns on sharding and allows separate control over the unit of write parallelism. So if you specifychunksalone, it controls thechunks/chunk_grid.chunk_shapeattributes, but if you specifychunksandshardstogether, thechunkscontrols thechunk_shapeattribute of the sharding codec config, andshardscontrols thechunks/chunk_grid.chunk_shapeattributes. IMO we should try to be consistent with this terminology, which argues for normalizing "shards" as the in-memory name for thechunks/chunk_grid.chunk_shapeattributes.