Skip to content

Commit

Permalink
Improve code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Jul 20, 2024
1 parent b7fb391 commit 18e3ecc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lindi/LindiH5ZarrStore/LindiH5ZarrStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ def close(self):
def __getitem__(self, key):
val = self._get_helper(key)

# Here's the hack
# If the key is a chunk and it's smaller than the expected size, then we
# need to pad it with zeros. This can happen if this is the final chunk
# in a contiguous hdf5 dataset. See
# https://github.com/NeurodataWithoutBorders/lindi/pull/84
base_key = key.split('/')[-1]
if val and _is_chunk_base_key(base_key):
parent_key = key.split('/')[:-1]
Expand All @@ -238,9 +241,10 @@ def __getitem__(self, key):
chunk_shape = zarray['chunks']
dtype = zarray['dtype']
expected_chunk_size = int(np.prod(chunk_shape)) * _get_itemsize(dtype)
if len(val) != expected_chunk_size:
# we need to pad it
if len(val) < expected_chunk_size:
val = _pad_chunk(val, expected_chunk_size)
elif len(val) > expected_chunk_size:
raise Exception(f"Chunk size is larger than expected: {len(val)} > {expected_chunk_size}")

return val

Expand Down
10 changes: 7 additions & 3 deletions lindi/LindiH5pyFile/LindiReferenceFileSystemStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def __contains__(self, key: object):
def __getitem__(self, key: str):
val = self._get_helper(key)

# Here's the hack
# If the key is a chunk and it's smaller than the expected size, then we
# need to pad it with zeros. This can happen if this is the final chunk
# in a contiguous hdf5 dataset. See
# https://github.com/NeurodataWithoutBorders/lindi/pull/84
base_key = key.split('/')[-1]
if val and _is_chunk_base_key(base_key):
parent_key = key.split('/')[:-1]
Expand All @@ -136,9 +139,10 @@ def __getitem__(self, key: str):
chunk_shape = zarray['chunks']
dtype = zarray['dtype']
expected_chunk_size = int(np.prod(chunk_shape)) * _get_itemsize(dtype)
if len(val) != expected_chunk_size:
# we need to pad it
if len(val) < expected_chunk_size:
val = _pad_chunk(val, expected_chunk_size)
elif len(val) > expected_chunk_size:
raise Exception(f"Chunk size is larger than expected: {len(val)} > {expected_chunk_size}")

return val

Expand Down

0 comments on commit 18e3ecc

Please sign in to comment.