zarr-python icon indicating copy to clipboard operation
zarr-python copied to clipboard

Reserved n5 attributes cannot be set in groups

Open constantinpape opened this issue 4 years ago • 2 comments

When using zarr with n5 backend, it's currently not possible to write the attributes that are restricted for usage in n5 datasets (for example dataType).

Minimal, reproducible code sample, a copy-pastable example if possible

import zarr
f = zarr.open('test.n5')
f.attrs['dataType'] = 'uint8'

fails with

Traceback (most recent call last):
  File "n5_attrs.py", line 4, in <module>
    f.attrs['dataType'] = 'uint8'
  File "/home/pape/Work/software/conda/miniconda3/envs/main/lib/python3.7/site-packages/zarr/attrs.py", line 79, in __setitem__
    self._write_op(self._setitem_nosync, item, value)
  File "/home/pape/Work/software/conda/miniconda3/envs/main/lib/python3.7/site-packages/zarr/attrs.py", line 73, in _write_op
    return f(*args, **kwargs)
  File "/home/pape/Work/software/conda/miniconda3/envs/main/lib/python3.7/site-packages/zarr/attrs.py", line 90, in _setitem_nosync
    self._put_nosync(d)
  File "/home/pape/Work/software/conda/miniconda3/envs/main/lib/python3.7/site-packages/zarr/attrs.py", line 112, in _put_nosync
    self.store[self.key] = json_dumps(d)
  File "/home/pape/Work/software/conda/miniconda3/envs/main/lib/python3.7/site-packages/zarr/n5.py", line 130, in __setitem__
    raise ValueError("Can not set attribute %s, this is a reserved N5 keyword" % k)
ValueError: Can not set attribute dataType, this is a reserved N5 keyword

Problem description

There is no reason to restrict the usage of restricted dataset keys for groups. In particular, the bigdataviewer n5 format uses the key dataType as group metadata, so it's currently not possible to write data in this format with zarr.n5.

Version and installation information

Please provide the following:

  • Value of zarr.__version__: 2.6.1
  • Value of numcodecs.__version__: 0.6.4
  • Version of Python interpreter: 3.7.8
  • Operating system: Linux
  • How Zarr was installed: using conda

constantinpape avatar Jan 21 '21 10:01 constantinpape

Still an issue? And with @d-v-b's new version?

joshmoore avatar Sep 22 '21 13:09 joshmoore

I would guess that this is an issue in my version, but it should be simple to fix.

d-v-b avatar Sep 22 '21 13:09 d-v-b