Skip to content

Commit

Permalink
Forward mode option through normalize store args.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Nov 30, 2020
1 parent da4f790 commit a8dfb64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions docs/release.rst
Expand Up @@ -10,6 +10,9 @@ This release will be the first release of Zarr not supporting Python 3.5.
* End Python 3.5 support.
By :user:`Chris Barnes <clbarnes>`; :issue:`602`.

* Fix ``open_group/open_array`` to allow opening of readonly store with
``mode='r'`` :issue:`269`

* Add `Array` tests for FSStore.
By :user:`Andrew Fulton <andrewfulton9>`; :issue: `644`.

Expand Down
8 changes: 4 additions & 4 deletions zarr/creation.py
Expand Up @@ -129,11 +129,11 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, storage_options=None):
def normalize_store_arg(store, clobber=False, storage_options=None, mode='w'):
if store is None:
return dict()
elif isinstance(store, str):
mode = 'w' if clobber else 'r'
mode = mode if clobber else "r"
if "://" in store or "::" in store:
return FSStore(store, mode=mode, **(storage_options or {}))
elif storage_options:
Expand Down Expand Up @@ -450,8 +450,8 @@ def open_array(store=None, mode='a', shape=None, chunks=True, dtype=None,
# a : read/write if exists, create otherwise (default)

# handle polymorphic store arg
clobber = mode == 'w'
store = normalize_store_arg(store, clobber=clobber, storage_options=storage_options)
clobber = (mode == 'w')
store = normalize_store_arg(store, clobber=clobber, storage_options=storage_options, mode=mode)
if chunk_store is not None:
chunk_store = normalize_store_arg(chunk_store, clobber=clobber,
storage_options=storage_options)
Expand Down
10 changes: 6 additions & 4 deletions zarr/hierarchy.py
Expand Up @@ -1035,11 +1035,11 @@ def move(self, source, dest):
self._write_op(self._move_nosync, source, dest)


def _normalize_store_arg(store, clobber=False, storage_options=None):
def _normalize_store_arg(store, *, clobber=False, storage_options=None, mode=None):
if store is None:
return MemoryStore()
return normalize_store_arg(store, clobber=clobber,
storage_options=storage_options)
storage_options=storage_options, mode=mode)


def group(store=None, overwrite=False, chunk_store=None,
Expand Down Expand Up @@ -1148,8 +1148,10 @@ def open_group(store=None, mode='a', cache_attrs=True, synchronizer=None, path=N
"""

# handle polymorphic store arg
clobber = mode != 'r'
store = _normalize_store_arg(store, clobber=clobber, storage_options=storage_options)
clobber = mode != "r"
store = _normalize_store_arg(
store, clobber=clobber, storage_options=storage_options, mode=mode
)
if chunk_store is not None:
chunk_store = _normalize_store_arg(chunk_store, clobber=clobber,
storage_options=storage_options)
Expand Down

0 comments on commit a8dfb64

Please sign in to comment.