Repository navigation
fix(ome_zarr): 🐛 preserve dimension names during resharding - #48
Conversation
lguerard
left a comment
There was a problem hiding this comment.
Thanks, this looks good: it goes through the existing creation path, unnamed arrays stay unnamed, and the test covers the three cases.
One optional change, if you have a minute: _to_zarr_level only honours dimension_names on its sharded branch. reshard_level can't reach the unsharded one (v2 returns early, and on v3 a truthy shard always gives a shard tuple), so #47 is fixed either way. The point is that the parameter should mean the same on both branches. GitHub won't take suggestion blocks outside the diff, so here are the two other spots:
def _create_level_array(
group: "zarr.Group",
name: str,
shape: tuple[int, ...],
chunks: tuple[int, ...],
dtype,
+ dimension_names: tuple[str | None, ...] | None = None,
) -> "zarr.Array":
"""Create (replacing any existing) a pyramid level array in *group*.
Parameters
----------
...
dtype : dtype-like
Its dtype.
+ dimension_names : tuple of (str or None) or None, optional
+ Names for the array's dimensions; default none.
Returns
-------
zarr.Array
"""
if name in group:
del group[name]
kwargs = zarr_compressor_kwargs(_group_zarr_format(group))
return group.create_array(
- name, shape=shape, chunks=chunks, dtype=dtype, **kwargs
+ name,
+ shape=shape,
+ chunks=chunks,
+ dtype=dtype,
+ dimension_names=dimension_names,
+ **kwargs,
) z = _create_level_array(
_open_group(group_path),
component,
arr.shape,
arr.chunksize,
arr.dtype,
+ dimension_names=dimension_names,
)Behaviour is unchanged for every existing caller, since the default is None. A zarr v2 array accepts dimension_names=None but raises ValueError for real names, so a future v2 caller passing names would fail loudly rather than drop them. The docstring suggestion below goes with it.
Generated by Claude Code
| then cut straight into shards: blocks as small as a viewer's chunks | ||
| (one plane of 512 x 512) would make millions of tasks. | ||
| dimension_names : tuple of (str or None) or None, optional | ||
| Existing dimension names to preserve when writing a sharded level. |
There was a problem hiding this comment.
With the unsharded branch passing the names too, the docstring no longer needs to restrict it:
| Existing dimension names to preserve when writing a sharded level. | |
| Names for the new array's dimensions, e.g. the original's when | |
| resharding; default none. |
Generated by Claude Code
|
Thanks a lot for this ! It'll be included in the next release or available immediately from GitHub ! |
Thanks for confirming the issue.
As suggested, this passes the existing dimension_names to _to_zarr_level() when creating the replacement array, so it goes through the existing array creation path.
Unnamed staging arrays stay unnamed until metadata finalization, and no names are inferred from the group axes.
Tests:
Local verification (Linux):
One note, the Cellpose doctest is hardware-dependent and fails the same way on both the base revision and this branch when CPU affinity is unrestricted. With affinity limited to two CPUs, both pass (46 passed, 24 skipped), so this failure is unrelated to the change.
Fixes #47