Skip to content

Commit

Permalink
Use zip() or enumerate() instead of range(len())
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Jul 21, 2024
1 parent 57acd81 commit 7f79d3d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions blosc2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,23 +1275,23 @@ def compute_chunks_blocks(
blocks = [blocks]
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:
for block, dim in zip(blocks, shape):
if block == 0:
raise ValueError("blocks cannot contain 0 dimension")
if shape[i] == 1 and blocks[i] > shape[i]:
if dim == 1 and block > dim:
raise ValueError("blocks cannot be greater than shape if it is 1")
if chunks:
if not isinstance(chunks, tuple | list):
chunks = [chunks]
if len(chunks) != len(shape):
raise ValueError("chunks should have the same length than shape")
for i in range(len(chunks)):
if shape[i] == 1 and chunks[i] > shape[i]:
for chunk, dim in zip(chunks, shape):
if dim == 1 and chunk > dim:
raise ValueError("chunks cannot be greater than shape if it is 1")

if chunks is not None and blocks is not None:
for i in range(len(blocks)):
if blocks[i] > chunks[i]:
for block, chunk in zip(blocks, chunks):
if block > chunk:
raise ValueError("blocks cannot be greater than chunks")
return chunks, blocks

Expand Down
12 changes: 6 additions & 6 deletions tests/ndarray/test_auto_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def test_compute_chunks_blocks(clevel, codec, shape: tuple, dtype):
else:
chunks, blocks = blosc2.compute_chunks_blocks(shape, **cparams)
# print(chunks, blocks)
for i in range(len(shape)):
assert shape[i] >= chunks[i]
assert chunks[i] >= blocks[i]
for dim, chunk, block in zip(shape, chunks, blocks):
assert dim >= chunk
assert chunk >= block


@pytest.mark.parametrize(
Expand All @@ -65,9 +65,9 @@ def test_compute_chunks_blocks(clevel, codec, shape: tuple, dtype):
def test_compute_chunks(shape: tuple, blocks: tuple):
chunks, blocks = blosc2.compute_chunks_blocks(shape, blocks=blocks)
# print(chunks, blocks)
for i in range(len(shape)):
assert shape[i] >= chunks[i]
assert chunks[i] >= blocks[i]
for dim, chunk, block in zip(shape, chunks, blocks):
assert dim >= chunk
assert chunk >= block


# Invalid blocks
Expand Down
4 changes: 2 additions & 2 deletions tests/ndarray/test_lazyexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ def test_save():
a4 = blosc2.asarray(na4)
ops = [a1, a2, a3, a4]
op_urlpaths = ["a1.b2nd", "a2.b2nd", "a3.b2nd", "a4.b2nd"]
for i in range(len(op_urlpaths)):
ops[i] = ops[i].copy(urlpath=op_urlpaths[i], mode="w")
for i, urlpath in enumerate(op_urlpaths):
ops[i] = ops[i].copy(urlpath=urlpath, mode="w")

# Construct the lazy expression with the on-disk operands
da1, da2, da3, da4 = ops
Expand Down

0 comments on commit 7f79d3d

Please sign in to comment.