Skip to content

Commit

Permalink
update backend imports for optional zarr
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Nov 27, 2024
1 parent 72779d5 commit be666b6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,16 @@ def get_sum(self, a, b):
@docval({'name': 'path', 'type': str, 'doc': 'the neurodata_type to get the NWBContainer class for'},
is_method=False)
def _get_backend(path: str):
from hdmf_zarr import NWBZarrIO
try:
from hdmf_zarr import NWBZarrIO
backend_io_classes = [NWBHDF5IO, NWBZarrIO]
except ImportError:
backend_io_classes = [NWBHDF5IO]

backend_io_classes = [NWBHDF5IO, NWBZarrIO]
backend_options = [b for b in backend_io_classes if b.can_read(path=path)]
if len(backend_options) == 0:
raise ValueError(f"Could not find an IO to read the file '{path}'.")
raise ValueError(f"Could not find an IO to read the file '{path}'. If you are trying to read "
f"a Zarr file, make sure you have hdmf-zarr installed.")
else:
return backend_options[0]

Expand Down

0 comments on commit be666b6

Please sign in to comment.