Summary
After rebuilding a fresh environment SpatialData.write() started failing.
The same code works in an older environment with the same spatialdata, dask, and zarr versions, but with ome-zarr==0.13.0 instead of 0.14.0.
This looks like a regression at the spatialdata / ome-zarr boundary when chunks are passed from xarray/dask to the writer.
Minimal reproducer
importosimporttempfilefromspatialdata.datasetsimportblobssdata=blobs()
out=os.path.join(tempfile.gettempdir(), "sd_blobs_write_issue.zarr")
sdata.write(out)
Observed behavior
The call to sdata.write(out) raises:
TypeError: Expectedaniterableofintegers. Got ((3,), (512,), (512,)) instead.
Full traceback
Traceback (mostrecentcalllast):
File"<stdin>", line9, in<module>File".../site-packages/spatialdata/_utils.py", line263, inwrapperreturnf(*args, **kwargs)
File".../site-packages/spatialdata/_core/spatialdata.py", line1176, inwriteself._write_element(
File".../site-packages/spatialdata/_core/spatialdata.py", line1229, in_write_elementwrite_image(
File".../site-packages/spatialdata/_io/io_raster.py", line371, inwrite_image_write_raster(
File".../site-packages/spatialdata/_io/io_raster.py", line197, in_write_raster_write_raster_dataarray(
File".../site-packages/spatialdata/_io/io_raster.py", line275, in_write_raster_dataarraywrite_single_scale_ngff(
File".../site-packages/ome_zarr/writer.py", line651, inwrite_imagedask_delayed_jobs=_write_pyramid_to_zarr(
File".../site-packages/ome_zarr/writer.py", line754, in_write_pyramid_to_zarrda.to_zarr(
File".../site-packages/dask/array/core.py", line4101, into_zarrz=root.create_array(name=array_name, **zarr_array_kwargs)
File".../site-packages/zarr/core/group.py", line2715, increate_arrayself._sync(
File".../site-packages/zarr/core/array.py", line777, in_create_metadata_v3chunk_grid_parsed=RegularChunkGrid(chunk_shape=chunk_shape)
File".../site-packages/zarr/core/chunk_grids.py", line180, in__init__chunk_shape_parsed=parse_shapelike(chunk_shape)
File".../site-packages/zarr/core/common.py", line200, inparse_shapelikeraiseTypeError(msg)
TypeError: Expectedaniterableofintegers. Got ((3,), (512,), (512,)) instead.
Version comparison
Failing environment:
Python 3.12.12
spatialdata 0.7.2
ome-zarr 0.14.0
zarr 3.1.5
dask 2026.1.1
Working environment:
Python 3.12.12
spatialdata 0.7.2
ome-zarr 0.13.0
zarr 3.1.5
dask 2026.1.1
So the only relevant version difference I found between the two environments is ome-zarr.
Suspected cause
It looks like spatialdata passes xarray/dask chunk metadata in the form returned by .chunks, i.e. a tuple of tuples:
In spatialdata/_io/io_raster.py, raster_data.chunks is forwarded into storage_options["chunks"]:
chunks=raster_data.chunks
...
storage_options= {"chunks": chunks}Then in ome_zarr/writer.py, that value is forwarded into zarr_array_kwargs["chunks"]:
chunks_opt=options.pop("chunks", None)
...
zarr_array_kwargs["chunks"] =chunks_optBut zarr expects a flat chunk shape like:
not the dask chunk grid:
Expected behavior
blobs().write(path) should succeed, or the chunk metadata should be normalized before being passed to Zarr.
Workaround
Pinning ome-zarr==0.13.0 avoids the problem in my setup.
Summary
After rebuilding a fresh environment
SpatialData.write()started failing.The same code works in an older environment with the same
spatialdata,dask, andzarrversions, but withome-zarr==0.13.0instead of0.14.0.This looks like a regression at the
spatialdata/ome-zarrboundary whenchunksare passed from xarray/dask to the writer.Minimal reproducer
Observed behavior
The call to
sdata.write(out)raises:Full traceback
Version comparison
Failing environment:
Working environment:
So the only relevant version difference I found between the two environments is
ome-zarr.Suspected cause
It looks like
spatialdatapasses xarray/dask chunk metadata in the form returned by.chunks, i.e. a tuple of tuples:In
spatialdata/_io/io_raster.py,raster_data.chunksis forwarded intostorage_options["chunks"]:Then in
ome_zarr/writer.py, that value is forwarded intozarr_array_kwargs["chunks"]:But
zarrexpects a flat chunk shape like:not the dask chunk grid:
Expected behavior
blobs().write(path)should succeed, or the chunk metadata should be normalized before being passed to Zarr.Workaround
Pinning
ome-zarr==0.13.0avoids the problem in my setup.