Skip to content

Commit 4a03219

Browse files
Use list comprehension where applicable
Even if this is only a test, list comprehensions are faster than repeatedly call append(). Also use tuple instead of list when possible.
1 parent 71ce63a commit 4a03219

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

zarr/tests/test_indexing.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,17 +1754,15 @@ def test_accessed_chunks(shape, chunks, ops):
17541754
for ii, (optype, slices) in enumerate(ops):
17551755

17561756
# Resolve the slices into the accessed chunks for each dimension
1757-
chunks_per_dim = []
1758-
for N, C, sl in zip(shape, chunks, slices):
1759-
chunk_ind = np.arange(N, dtype=int)[sl] // C
1760-
chunks_per_dim.append(np.unique(chunk_ind))
1757+
chunks_per_dim = [
1758+
np.unique(np.arange(N, dtype=int)[sl] // C) for N, C, sl in zip(shape, chunks, slices)
1759+
]
17611760

17621761
# Combine and generate the cartesian product to determine the chunks keys that
17631762
# will be accessed
1764-
chunks_accessed = []
1765-
for comb in itertools.product(*chunks_per_dim):
1766-
chunks_accessed.append(".".join([str(ci) for ci in comb]))
1767-
1763+
chunks_accessed = (
1764+
".".join([str(ci) for ci in comb]) for comb in itertools.product(*chunks_per_dim)
1765+
)
17681766
counts_before = store.counter.copy()
17691767

17701768
# Perform the operation

0 commit comments

Comments
 (0)