Skip to content

Commit 505810c

Browse files
Use generator instead of list comprehension (#1139)
Using a container in place of a generator for calls that can accept both, slows down the performance. Consider using generators for all function calls which accept both containers and genertors.
1 parent 9f4e3b1 commit 505810c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

zarr/_storage/v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def setitems(self, values):
153153
# initialize the /data/root/... folder corresponding to the array!
154154
# Note: zarr.tests.test_core_v3.TestArrayWithFSStoreV3PartialRead fails
155155
# without this explicit creation of directories
156-
subdirectories = set([os.path.dirname(v) for v in values.keys()])
156+
subdirectories = set(os.path.dirname(v) for v in values.keys())
157157
for subdirectory in subdirectories:
158158
data_dir = os.path.join(self.path, subdirectory)
159159
if not self.fs.exists(data_dir):

zarr/indexing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def ix_(selection, shape):
559559
def oindex(a, selection):
560560
"""Implementation of orthogonal indexing with slices and ints."""
561561
selection = replace_ellipsis(selection, a.shape)
562-
drop_axes = tuple([i for i, s in enumerate(selection) if is_integer(s)])
562+
drop_axes = tuple(i for i, s in enumerate(selection) if is_integer(s))
563563
selection = ix_(selection, a.shape)
564564
result = a[selection]
565565
if drop_axes:
@@ -569,7 +569,7 @@ def oindex(a, selection):
569569

570570
def oindex_set(a, selection, value):
571571
selection = replace_ellipsis(selection, a.shape)
572-
drop_axes = tuple([i for i, s in enumerate(selection) if is_integer(s)])
572+
drop_axes = tuple(i for i, s in enumerate(selection) if is_integer(s))
573573
selection = ix_(selection, a.shape)
574574
if not np.isscalar(value) and drop_axes:
575575
value = np.asanyarray(value)
@@ -623,8 +623,8 @@ def __init__(self, selection, array):
623623
if not isinstance(s, IntDimIndexer))
624624
self.is_advanced = not is_basic_selection(selection)
625625
if self.is_advanced:
626-
self.drop_axes = tuple([i for i, dim_indexer in enumerate(self.dim_indexers)
627-
if isinstance(dim_indexer, IntDimIndexer)])
626+
self.drop_axes = tuple(i for i, dim_indexer in enumerate(self.dim_indexers)
627+
if isinstance(dim_indexer, IntDimIndexer))
628628
else:
629629
self.drop_axes = None
630630

0 commit comments

Comments
 (0)