From a39b7f8524454ff4a82103ccb6bc637e15f26797 Mon Sep 17 00:00:00 2001 From: rly Date: Mon, 13 May 2024 19:29:53 -0700 Subject: [PATCH] Fix for case when chunk_iter is not available --- lindi/LindiH5ZarrStore/LindiH5ZarrStore.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lindi/LindiH5ZarrStore/LindiH5ZarrStore.py b/lindi/LindiH5ZarrStore/LindiH5ZarrStore.py index 0ee1d15..f4bdab6 100644 --- a/lindi/LindiH5ZarrStore/LindiH5ZarrStore.py +++ b/lindi/LindiH5ZarrStore/LindiH5ZarrStore.py @@ -492,8 +492,13 @@ def _add_chunk_info_to_refs( ) assert chunk_index == _get_chunk_index(h5_item, chunk_coords) - byte_offset = chunk_info[chunk_index].byte_offset - byte_count = chunk_info[chunk_index].size + # use chunk_info if available on this system because it is more efficient, + # otherwise use the slower _get_chunk_byte_range + if chunk_info is not None: + byte_offset = chunk_info[chunk_index].byte_offset + byte_count = chunk_info[chunk_index].size + else: + byte_offset, byte_count = _get_chunk_byte_range(h5_item, chunk_coords) except Exception as e: raise Exception( f"Error getting byte range for chunk {key_parent}/{key_name}. Shape: {h5_item.shape}, Chunks: {h5_item.chunks}, Chunk coords: {chunk_coords}: {e}"