From cccff69cc507582d19156c6b6bc140f32d7c5615 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Fri, 18 Sep 2020 13:55:58 -0700 Subject: [PATCH] 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. --- zarr/convenience.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/zarr/convenience.py b/zarr/convenience.py index c0ae2d08fe..7b39abcd54 100644 --- a/zarr/convenience.py +++ b/zarr/convenience.py @@ -83,12 +83,8 @@ def open(store=None, mode='a', **kwargs): else: return open_group(store, mode=mode, **kwargs) - elif mode == 'a': - if contains_array(store, path): - return open_array(store, mode=mode, **kwargs) - elif contains_group(store, path): - return open_group(store, mode=mode, **kwargs) - elif 'shape' in kwargs: + elif mode == "a": + if "shape" in kwargs or contains_array(store, path): return open_array(store, mode=mode, **kwargs) else: return open_group(store, mode=mode, **kwargs)