Skip to content

Commit baab540

Browse files
authored
Merge pull request #660 from Carreau/zopen-r
Forward mode option through normalize store args.
2 parents 88fd131 + a8dfb64 commit baab540

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ This release will be the first release of Zarr not supporting Python 3.5.
1010
* End Python 3.5 support.
1111
By :user:`Chris Barnes <clbarnes>`; :issue:`602`.
1212

13+
* Fix ``open_group/open_array`` to allow opening of readonly store with
14+
``mode='r'`` :issue:`269`
15+
1316
* Add `Array` tests for FSStore.
1417
By :user:`Andrew Fulton <andrewfulton9>`; :issue: `644`.
1518

zarr/creation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ def create(shape, chunks=True, dtype=None, compressor='default',
129129
return z
130130

131131

132-
def normalize_store_arg(store, clobber=False, storage_options=None):
132+
def normalize_store_arg(store, clobber=False, storage_options=None, mode='w'):
133133
if store is None:
134134
return dict()
135135
elif isinstance(store, str):
136-
mode = 'w' if clobber else 'r'
136+
mode = mode if clobber else "r"
137137
if "://" in store or "::" in store:
138138
return FSStore(store, mode=mode, **(storage_options or {}))
139139
elif storage_options:
@@ -450,8 +450,8 @@ def open_array(store=None, mode='a', shape=None, chunks=True, dtype=None,
450450
# a : read/write if exists, create otherwise (default)
451451

452452
# handle polymorphic store arg
453-
clobber = mode == 'w'
454-
store = normalize_store_arg(store, clobber=clobber, storage_options=storage_options)
453+
clobber = (mode == 'w')
454+
store = normalize_store_arg(store, clobber=clobber, storage_options=storage_options, mode=mode)
455455
if chunk_store is not None:
456456
chunk_store = normalize_store_arg(chunk_store, clobber=clobber,
457457
storage_options=storage_options)

zarr/hierarchy.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,11 +1035,11 @@ def move(self, source, dest):
10351035
self._write_op(self._move_nosync, source, dest)
10361036

10371037

1038-
def _normalize_store_arg(store, clobber=False, storage_options=None):
1038+
def _normalize_store_arg(store, *, clobber=False, storage_options=None, mode=None):
10391039
if store is None:
10401040
return MemoryStore()
10411041
return normalize_store_arg(store, clobber=clobber,
1042-
storage_options=storage_options)
1042+
storage_options=storage_options, mode=mode)
10431043

10441044

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

11501150
# handle polymorphic store arg
1151-
clobber = mode != 'r'
1152-
store = _normalize_store_arg(store, clobber=clobber, storage_options=storage_options)
1151+
clobber = mode != "r"
1152+
store = _normalize_store_arg(
1153+
store, clobber=clobber, storage_options=storage_options, mode=mode
1154+
)
11531155
if chunk_store is not None:
11541156
chunk_store = _normalize_store_arg(chunk_store, clobber=clobber,
11551157
storage_options=storage_options)

0 commit comments

Comments
 (0)