hdmf-dev / hdmf-zarr

Zarr I/O backend for HDMF
https://hdmf-zarr.readthedocs.io/
Other
7 stars 7 forks source link

[Feature]: Expose `mode` to NWBZarrIO #137

Open CodyCBakerPhD opened 10 months ago

CodyCBakerPhD commented 10 months ago

What would you like to see added to HDMF-ZARR?

Stems from https://github.com/catalystneuro/neuroconv/pull/569#discussion_r1342411702

The NWBHDF5IO has a .mode attribute publicly exposed to easily detect on an instantiated IO object what the mode was at time of instantiation (useful for determining if an in-memory NWBFile object was read from an existing file or created on the fly)

But the NWBZarrIO does not; though the same info can be accessed via the private ._ZarrIO__mode attribute

Is your feature request related to a problem?

from hdmf_zarr import NWBZarrIO

io = NWBZarrIO(path="../test2.nwb.zarr", mode="r")

io.mode

Traceback (most recent call last):

  Cell In[4], line 1
    io.mode

AttributeError: 'NWBZarrIO' object has no attribute 'mode'

What solution would you like?

Expose .mode attribute as public instead of _ZarrIO__mode

Do you have any interest in helping implement the feature?

No.

Code of Conduct

oruebel commented 10 months ago

I think NWBZarrIO.file.mode should do the trick.

CodyCBakerPhD commented 10 months ago
io.file.mode
Traceback (most recent call last):

  File ~\AppData\Roaming\Python\Python310\site-packages\zarr\hierarchy.py:520 in __getattr__
    return self.__getitem__(item)

  File ~\AppData\Roaming\Python\Python310\site-packages\zarr\hierarchy.py:500 in __getitem__
    raise KeyError(item)

KeyError: 'mode'

Also, more to the original issue as requested by @bendichter, he wanted a universal API consistency with NWBHDF5IO in this respect

oruebel commented 10 months ago

If I remember correctly not all stores in Zarr actually support mode. The standard NestedDirectoryStore, e.g., I believe does not have a mode

oruebel commented 10 months ago

Looking at https://zarr.readthedocs.io/en/stable/api/storage.html#zarr.storage.DirectoryStore (which is what Zarr uses by default), does not have a mode. The convenience functions zarr.convenience.open and other have a mode but I'm not sure right now where that is being stored (maybe, NWBZarrIO.file.store.mode)