ome / ome-zarr-py

Implementation of next-generation file format (NGFF) specifications for storing bioimaging data in the cloud.
https://pypi.org/project/ome-zarr
Other
152 stars 54 forks source link

parse_url in write mode does not truncate #97

Open constantinpape opened 3 years ago

constantinpape commented 3 years ago

Passing mode=w to parse_url does not truncate existing files as it should. Minimal example:

import numpy as np
import ome_zarr.writer
import zarr
file_path = "my.ome.zarr"
loc = ome_zarr.io.parse_url(file_path, mode="w")
group = zarr.group(loc.store)
shape = (1, 1, 1, 256, 256)
ome_zarr.writer.write_image(np.random.rand(*shape), group)

Fails with ContainsArrayError: path '0' contains an array when run the second time.

joshmoore commented 3 years ago

I've definitely run into this before, but I would think this is coming directly from zarr-python (unless you think the mode isn't being passed somewhere)

dstansby commented 3 months ago

Having a look at this, I agree it's coming from zarr-python. The issue is init_array takes an overwrite argument, which defaults to False and doesn't take into account the file mode of the store (which is what's being passed in the example above). I haven't time now, but should be possible to cook up a zarr-python-only reproducible example.

This is probably also the same issue as https://github.com/ome/ome-zarr-py/issues/376