diff --git a/lindi/LindiH5ZarrStore/LindiH5ZarrStore.py b/lindi/LindiH5ZarrStore/LindiH5ZarrStore.py index 14a4e3f..d83332e 100644 --- a/lindi/LindiH5ZarrStore/LindiH5ZarrStore.py +++ b/lindi/LindiH5ZarrStore/LindiH5ZarrStore.py @@ -1,6 +1,6 @@ import json import base64 -from typing import Tuple, Union, List, IO, Any, Dict +from typing import Tuple, Union, List, IO, Any, Dict, Callable import numpy as np import zarr from zarr.storage import Store, MemoryStore @@ -429,10 +429,13 @@ def _add_chunk_info_to_refs( self, key_parent: str, key_names: List[str], - add_ref: callable, - add_ref_chunk: callable + add_ref: Callable, + add_ref_chunk: Callable ): + if self._h5f is None: + raise Exception("Store is closed") h5_item = self._h5f.get('/' + key_parent, None) + assert isinstance(h5_item, h5py.Dataset) # For the case of a scalar dataset, we need to check a few things if h5_item.ndim == 0: @@ -449,7 +452,7 @@ def _add_chunk_info_to_refs( if inline_array.is_inline: if len(key_names) != 1 or key_names[0] != inline_array.chunk_fname: raise Exception( - f"Chunk name {key_name[0]} does not match dataset dimensions for inline array {key_parent}" + f"Chunk name {key_names[0]} does not match dataset dimensions for inline array {key_parent}" ) inline_data = inline_array.chunk_bytes add_ref(f"{key_parent}/{key_names[0]}", inline_data) @@ -470,6 +473,7 @@ def _add_chunk_info_to_refs( leave=True, delay=2 # do not show progress bar until 2 seconds have passed ): + chunk_coords = None # so that chunk_coords is not unbound on exception try: # TODO remove this code through the assert after verifying order of key_names # Get the chunk coords from the file name diff --git a/lindi/LindiH5ZarrStore/_util.py b/lindi/LindiH5ZarrStore/_util.py index b3b43ee..b310084 100644 --- a/lindi/LindiH5ZarrStore/_util.py +++ b/lindi/LindiH5ZarrStore/_util.py @@ -54,6 +54,7 @@ def _get_chunk_index(h5_dataset: h5py.Dataset, chunk_coords: tuple) -> int: chunk_index += int(chunk_coords[i] * np.prod(chunk_coords_shape[i + 1:])) return chunk_index + def _get_chunk_byte_range(h5_dataset: h5py.Dataset, chunk_coords: tuple) -> tuple: """Get the byte range in the file for a chunk of an h5py dataset.