Skip to content

Commit

Permalink
Use list comprehension where applicable (zarr-developers#1555)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
2 people authored and jhamman committed Jan 24, 2024
1 parent 0016e99 commit 3243e14
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions zarr/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1719,17 +1719,15 @@ def test_accessed_chunks(shape, chunks, ops):

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

# Combine and generate the cartesian product to determine the chunks keys that
# will be accessed
chunks_accessed = []
for comb in itertools.product(*chunks_per_dim):
chunks_accessed.append(".".join([str(ci) for ci in comb]))

chunks_accessed = (
".".join([str(ci) for ci in comb]) for comb in itertools.product(*chunks_per_dim)
)
counts_before = store.counter.copy()

# Perform the operation
Expand Down

0 comments on commit 3243e14

Please sign in to comment.