From be666b673a2f85aa78b5703214622f005827a89b Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:23:58 -0500 Subject: [PATCH] update backend imports for optional zarr --- src/pynwb/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pynwb/__init__.py b/src/pynwb/__init__.py index 64cc15cfb..6ccce7ee8 100644 --- a/src/pynwb/__init__.py +++ b/src/pynwb/__init__.py @@ -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]