Skip to content

Commit

Permalink
Check that chunks/blocks computation does not allow a 0 in blocks
Browse files Browse the repository at this point in the history
Fixes #165.
  • Loading branch information
ivilata committed Mar 25, 2024
1 parent 5878923 commit 33b1dfa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions blosc2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,8 @@ def compute_chunks_blocks(shape, chunks=None, blocks=None, dtype=np.uint8, **kwa
if len(blocks) != len(shape):
raise ValueError("blocks should have the same length than shape")
for i in range(len(blocks)):
if blocks[i] == 0:
raise ValueError("blocks cannot contain 0 dimension")
if blocks[i] > shape[i]:
raise ValueError("blocks cannot be greater than shape")
if chunks:
Expand Down
6 changes: 6 additions & 0 deletions tests/ndarray/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@ def test_empty_minimal(shape, dtype):
def test_cparams_chunks_blocks(shape, cparams):
with pytest.raises(ValueError):
blosc2.empty(shape, cparams=cparams)


def test_zero_in_blockshape():
# Check for #165
with pytest.raises(ValueError):
blosc2.empty(shape=(1200,), chunks=(100,), blocks=(0,))

0 comments on commit 33b1dfa

Please sign in to comment.