Skip to content

Commit 3243e14

Browse files
DimitriPapadopoulosd-v-b
authored andcommitted
Use list comprehension where applicable (zarr-developers#1555)
Even if this is only a test, list comprehensions are faster than repeatedly call append(). Also use tuple instead of list when possible. Co-authored-by: Davis Bennett <[email protected]>
1 parent 0016e99 commit 3243e14

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
@@ -1719,17 +1719,15 @@ def test_accessed_chunks(shape, chunks, ops):
17191719

17201720
for ii, (optype, slices) in enumerate(ops):
17211721
# Resolve the slices into the accessed chunks for each dimension
1722-
chunks_per_dim = []
1723-
for N, C, sl in zip(shape, chunks, slices):
1724-
chunk_ind = np.arange(N, dtype=int)[sl] // C
1725-
chunks_per_dim.append(np.unique(chunk_ind))
1722+
chunks_per_dim = [
1723+
np.unique(np.arange(N, dtype=int)[sl] // C) for N, C, sl in zip(shape, chunks, slices)
1724+
]
17261725

17271726
# Combine and generate the cartesian product to determine the chunks keys that
17281727
# will be accessed
1729-
chunks_accessed = []
1730-
for comb in itertools.product(*chunks_per_dim):
1731-
chunks_accessed.append(".".join([str(ci) for ci in comb]))
1732-
1728+
chunks_accessed = (
1729+
".".join([str(ci) for ci in comb]) for comb in itertools.product(*chunks_per_dim)
1730+
)
17331731
counts_before = store.counter.copy()
17341732

17351733
# Perform the operation

0 commit comments

Comments
 (0)