Skip to content

Commit cccff69

Browse files
committed
Reduce number of store queries in open(mode='a').
In case where 'shape' is passed as argument, this will avoid calling "contains_array" which does store queries, as well as avoid testign if the array contains a group as anyway this is what we were going to do in the else case. This does change behavior in edge case: - if shape is passed and the key is a group, we'll try to open as array instead of groups. - if contains_array or contains_group would have raise we might skip over those checks. Though both of the above case should not be found in user code and are bugs AFAICT, and would just fail differently.
1 parent 35d709a commit cccff69

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

zarr/convenience.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,8 @@ def open(store=None, mode='a', **kwargs):
8383
else:
8484
return open_group(store, mode=mode, **kwargs)
8585

86-
elif mode == 'a':
87-
if contains_array(store, path):
88-
return open_array(store, mode=mode, **kwargs)
89-
elif contains_group(store, path):
90-
return open_group(store, mode=mode, **kwargs)
91-
elif 'shape' in kwargs:
86+
elif mode == "a":
87+
if "shape" in kwargs or contains_array(store, path):
9288
return open_array(store, mode=mode, **kwargs)
9389
else:
9490
return open_group(store, mode=mode, **kwargs)

0 commit comments

Comments
 (0)