Skip to content

Commit 4da5183

Browse files
committed
coverage to 100%; readonly->read_only
1 parent d39b08f commit 4da5183

File tree

10 files changed

+168
-133
lines changed

10 files changed

+168
-133
lines changed

docs/api/sync.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ Synchronization (``zarr.sync``)
44

55
.. autoclass:: ThreadSynchronizer
66
.. autoclass:: ProcessSynchronizer
7-
.. autoclass:: SynchronizedArray

docs/tutorial.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ array with thread synchronization::
276276
>>> z = zarr.zeros((10000, 10000), chunks=(1000, 1000), dtype='i4',
277277
... synchronizer=zarr.ThreadSynchronizer())
278278
>>> z
279-
zarr.sync.SynchronizedArray((10000, 10000), int32, chunks=(1000, 1000), order=C)
279+
zarr.core.Array((10000, 10000), int32, chunks=(1000, 1000), order=C)
280280
compression: blosc; compression_opts: {'clevel': 5, 'cname': 'lz4', 'shuffle': 1}
281281
nbytes: 381.5M; nbytes_stored: 313; ratio: 1277955.3; initialized: 0/100
282-
store: builtins.dict; synchronizer: zarr.sync.ThreadSynchronizer
282+
store: builtins.dict
283+
synchronizer: zarr.sync.ThreadSynchronizer
283284

284285
This array is safe to read or write within a multi-threaded program.
285286

@@ -291,10 +292,11 @@ provided that all processes have access to a shared file system. E.g.::
291292
... chunks=(1000, 1000), dtype='i4',
292293
... synchronizer=synchronizer)
293294
>>> z
294-
zarr.sync.SynchronizedArray((10000, 10000), int32, chunks=(1000, 1000), order=C)
295+
zarr.core.Array((10000, 10000), int32, chunks=(1000, 1000), order=C)
295296
compression: blosc; compression_opts: {'clevel': 5, 'cname': 'lz4', 'shuffle': 1}
296297
nbytes: 381.5M; nbytes_stored: 313; ratio: 1277955.3; initialized: 0/100
297-
store: zarr.storage.DirectoryStore; synchronizer: zarr.sync.ProcessSynchronizer
298+
store: zarr.storage.DirectoryStore
299+
synchronizer: zarr.sync.ProcessSynchronizer
298300

299301
This array is safe to read or write from multiple processes.
300302

zarr/attrs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
class Attributes(MutableMapping):
1212

13-
def __init__(self, store, key='.zattrs', readonly=False,
13+
def __init__(self, store, key='.zattrs', read_only=False,
1414
synchronizer=None):
1515
self.store = store
1616
self.key = key
17-
self.readonly = readonly
17+
self.read_only = read_only
1818
self.synchronizer = synchronizer
1919

2020
def __contains__(self, x):
@@ -30,7 +30,7 @@ def _put(self, d):
3030
def _write_op(self, f, *args, **kwargs):
3131

3232
# guard condition
33-
if self.readonly:
33+
if self.read_only:
3434
raise ReadOnlyError('attributes are read-only')
3535

3636
# synchronization

zarr/core.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Array(object):
2727
Array store, already initialized.
2828
path : string, optional
2929
Storage path.
30-
readonly : bool, optional
30+
read_only : bool, optional
3131
True if array should be protected against modification.
3232
chunk_store : MutableMapping, optional
3333
Separate storage for chunks. If not provided, `store` will be used
@@ -40,7 +40,7 @@ class Array(object):
4040
store
4141
path
4242
name
43-
readonly
43+
read_only
4444
chunk_store
4545
shape
4646
chunks
@@ -67,7 +67,7 @@ class Array(object):
6767
6868
""" # flake8: noqa
6969

70-
def __init__(self, store, path=None, readonly=False, chunk_store=None,
70+
def __init__(self, store, path=None, read_only=False, chunk_store=None,
7171
synchronizer=None):
7272
# N.B., expect at this point store is fully initialized with all
7373
# configuration metadata fully specified and normalized
@@ -78,7 +78,7 @@ def __init__(self, store, path=None, readonly=False, chunk_store=None,
7878
self._key_prefix = self._path + '/'
7979
else:
8080
self._key_prefix = ''
81-
self._readonly = readonly
81+
self._read_only = read_only
8282
if chunk_store is None:
8383
self._chunk_store = store
8484
else:
@@ -106,7 +106,7 @@ def __init__(self, store, path=None, readonly=False, chunk_store=None,
106106

107107
# initialize attributes
108108
akey = self._key_prefix + attrs_key
109-
self._attrs = Attributes(store, key=akey, readonly=readonly,
109+
self._attrs = Attributes(store, key=akey, read_only=read_only,
110110
synchronizer=synchronizer)
111111

112112
def _flush_metadata(self):
@@ -139,9 +139,9 @@ def name(self):
139139
return None
140140

141141
@property
142-
def readonly(self):
142+
def read_only(self):
143143
"""A boolean, True if modification operations are not permitted."""
144-
return self._readonly
144+
return self._read_only
145145

146146
@property
147147
def chunk_store(self):
@@ -249,7 +249,7 @@ def __eq__(self, other):
249249
return (
250250
isinstance(other, Array) and
251251
self.store == other.store and
252-
self.readonly == other.readonly and
252+
self.read_only == other.read_only and
253253
self.path == other.path
254254
# N.B., no need to compare other properties, should be covered by
255255
# store comparison
@@ -453,7 +453,7 @@ def __setitem__(self, key, value):
453453
"""
454454

455455
# guard conditions
456-
if self._readonly:
456+
if self._read_only:
457457
raise ReadOnlyError('array is read-only')
458458

459459
# normalize selection
@@ -674,7 +674,7 @@ def __repr__(self):
674674
return r
675675

676676
def __getstate__(self):
677-
return self._store, self._path, self._readonly, self._chunk_store, \
677+
return self._store, self._path, self._read_only, self._chunk_store, \
678678
self._synchronizer
679679

680680
def __setstate__(self, state):
@@ -683,7 +683,7 @@ def __setstate__(self, state):
683683
def _write_op(self, f, *args, **kwargs):
684684

685685
# guard condition
686-
if self._readonly:
686+
if self._read_only:
687687
raise ReadOnlyError('array is read-only')
688688

689689
# synchronization

zarr/creation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def open_array(path, mode='a', shape=None, chunks=None, dtype=None,
263263
path : string
264264
Path to directory in file system in which to store the array.
265265
mode : {'r', 'r+', 'a', 'w', 'w-'}
266-
Persistence mode: 'r' means readonly (must exist); 'r+' means
266+
Persistence mode: 'r' means read only (must exist); 'r+' means
267267
read/write (must exist); 'a' means read/write (create if doesn't
268268
exist); 'w' means create (overwrite if exists); 'w-' means create
269269
(fail if exists).
@@ -320,7 +320,7 @@ def open_array(path, mode='a', shape=None, chunks=None, dtype=None,
320320

321321
# use same mode semantics as h5py, although N.B., here `path` is a
322322
# directory:
323-
# r : readonly, must exist
323+
# r : read only, must exist
324324
# r+ : read/write, must exist
325325
# w : create, delete if exists
326326
# w- or x : create, fail if exists
@@ -362,11 +362,11 @@ def open_array(path, mode='a', shape=None, chunks=None, dtype=None,
362362
compression_opts=compression_opts,
363363
fill_value=fill_value, order=order)
364364

365-
# determine readonly status
366-
readonly = mode == 'r'
365+
# determine read only status
366+
read_only = mode == 'r'
367367

368368
# instantiate array
369-
z = Array(store, readonly=readonly, synchronizer=synchronizer)
369+
z = Array(store, read_only=read_only, synchronizer=synchronizer)
370370

371371
return z
372372

zarr/hierarchy.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Group(Mapping):
2727
Group store, already initialized.
2828
path : string, optional
2929
Storage path.
30-
readonly : bool, optional
30+
read_only : bool, optional
3131
True if group should be protected against modification.
3232
chunk_store : MutableMapping, optional
3333
Separate storage for chunks. If not provided, `store` will be used
@@ -40,7 +40,7 @@ class Group(Mapping):
4040
store
4141
path
4242
name
43-
readonly
43+
read_only
4444
chunk_store
4545
synchronizer
4646
attrs
@@ -74,7 +74,7 @@ class Group(Mapping):
7474
7575
"""
7676

77-
def __init__(self, store, path=None, readonly=False, chunk_store=None,
77+
def __init__(self, store, path=None, read_only=False, chunk_store=None,
7878
synchronizer=None):
7979

8080
self._store = store
@@ -83,7 +83,7 @@ def __init__(self, store, path=None, readonly=False, chunk_store=None,
8383
self._key_prefix = self._path + '/'
8484
else:
8585
self._key_prefix = ''
86-
self._readonly = readonly
86+
self._read_only = read_only
8787
if chunk_store is None:
8888
self._chunk_store = store
8989
else:
@@ -106,7 +106,7 @@ def __init__(self, store, path=None, readonly=False, chunk_store=None,
106106

107107
# setup attributes
108108
akey = self._key_prefix + attrs_key
109-
self._attrs = Attributes(store, key=akey, readonly=readonly,
109+
self._attrs = Attributes(store, key=akey, read_only=read_only,
110110
synchronizer=synchronizer)
111111

112112
@property
@@ -131,9 +131,9 @@ def name(self):
131131
return '/'
132132

133133
@property
134-
def readonly(self):
134+
def read_only(self):
135135
"""A boolean, True if modification operations are not permitted."""
136-
return self._readonly
136+
return self._read_only
137137

138138
@property
139139
def chunk_store(self):
@@ -156,7 +156,7 @@ def __eq__(self, other):
156156
return (
157157
isinstance(other, Group) and
158158
self._store == other.store and
159-
self._readonly == other.readonly and
159+
self._read_only == other.read_only and
160160
self._path == other.path
161161
# N.B., no need to compare attributes, should be covered by
162162
# store comparison
@@ -223,7 +223,7 @@ def __repr__(self):
223223
return r
224224

225225
def __getstate__(self):
226-
return self._store, self._path, self._readonly, self._chunk_store, \
226+
return self._store, self._path, self._read_only, self._chunk_store, \
227227
self._synchronizer
228228

229229
def __setstate__(self, state):
@@ -291,11 +291,11 @@ def __getitem__(self, item):
291291
""" # flake8: noqa
292292
path = self._item_path(item)
293293
if contains_array(self._store, path):
294-
return Array(self._store, readonly=self._readonly, path=path,
294+
return Array(self._store, read_only=self._read_only, path=path,
295295
chunk_store=self._chunk_store,
296296
synchronizer=self._synchronizer)
297297
elif contains_group(self._store, path):
298-
return Group(self._store, readonly=self._readonly, path=path,
298+
return Group(self._store, read_only=self._read_only, path=path,
299299
chunk_store=self._chunk_store,
300300
synchronizer=self._synchronizer)
301301
else:
@@ -342,7 +342,7 @@ def groups(self):
342342
path = self._key_prefix + key
343343
if contains_group(self._store, path):
344344
yield key, Group(self._store, path=path,
345-
readonly=self._readonly,
345+
read_only=self._read_only,
346346
chunk_store=self._chunk_store,
347347
synchronizer=self._synchronizer)
348348

@@ -387,14 +387,14 @@ def arrays(self):
387387
path = self._key_prefix + key
388388
if contains_array(self._store, path):
389389
yield key, Array(self._store, path=path,
390-
readonly=self._readonly,
390+
read_only=self._read_only,
391391
chunk_store=self._chunk_store,
392392
synchronizer=self._synchronizer)
393393

394394
def _write_op(self, f, *args, **kwargs):
395395

396396
# guard condition
397-
if self._readonly:
397+
if self._read_only:
398398
raise ReadOnlyError('group is read-only')
399399

400400
# synchronization
@@ -449,7 +449,7 @@ def _create_group_nosync(self, name):
449449
raise KeyError(name)
450450
else:
451451
init_group(self._store, path=path, chunk_store=self._chunk_store)
452-
return Group(self._store, path=path, readonly=self._readonly,
452+
return Group(self._store, path=path, read_only=self._read_only,
453453
chunk_store=self._chunk_store,
454454
synchronizer=self._synchronizer)
455455

@@ -495,7 +495,7 @@ def _require_group_nosync(self, name):
495495
elif not contains_group(self._store, p):
496496
init_group(self._store, path=p, chunk_store=self._chunk_store)
497497

498-
return Group(self._store, path=path, readonly=self._readonly,
498+
return Group(self._store, path=path, read_only=self._read_only,
499499
chunk_store=self._chunk_store,
500500
synchronizer=self._synchronizer)
501501

@@ -644,7 +644,7 @@ def _require_dataset_nosync(self, name, shape, dtype=None, exact=False,
644644

645645
if contains_array(self._store, path):
646646
synchronizer = kwargs.get('synchronizer', self._synchronizer)
647-
a = Array(self._store, path=path, readonly=self._readonly,
647+
a = Array(self._store, path=path, read_only=self._read_only,
648648
chunk_store=self._chunk_store, synchronizer=synchronizer)
649649
shape = normalize_shape(shape)
650650
if shape != a.shape:
@@ -838,7 +838,7 @@ def group(store=None, overwrite=False, chunk_store=None, synchronizer=None):
838838
elif not contains_group(store):
839839
init_group(store, chunk_store=chunk_store)
840840

841-
return Group(store, readonly=False, chunk_store=chunk_store,
841+
return Group(store, read_only=False, chunk_store=chunk_store,
842842
synchronizer=synchronizer)
843843

844844

@@ -851,7 +851,7 @@ def open_group(path, mode='a', synchronizer=None):
851851
path : string
852852
Path to directory in file system in which to store the group.
853853
mode : {'r', 'r+', 'a', 'w', 'w-'}
854-
Persistence mode: 'r' means readonly (must exist); 'r+' means
854+
Persistence mode: 'r' means read only (must exist); 'r+' means
855855
read/write (must exist); 'a' means read/write (create if doesn't
856856
exist); 'w' means create (overwrite if exists); 'w-' means create
857857
(fail if exists).
@@ -910,7 +910,7 @@ def open_group(path, mode='a', synchronizer=None):
910910
else:
911911
init_group(store)
912912

913-
# determine readonly status
914-
readonly = mode == 'r'
913+
# determine read only status
914+
read_only = mode == 'r'
915915

916-
return Group(store, readonly=readonly, synchronizer=synchronizer)
916+
return Group(store, read_only=read_only, synchronizer=synchronizer)

zarr/tests/test_attrs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
class TestAttributes(unittest.TestCase):
1616

17-
def init_attributes(self, store, readonly=False):
18-
return Attributes(store, key='attrs', readonly=readonly)
17+
def init_attributes(self, store, read_only=False):
18+
return Attributes(store, key='attrs', read_only=read_only)
1919

2020
def test_storage(self):
2121

@@ -74,9 +74,9 @@ def test_iterators(self):
7474
eq({'bar', 42}, set(a.values()))
7575
eq({('foo', 'bar'), ('baz', 42)}, set(a.items()))
7676

77-
def test_readonly(self):
77+
def test_read_only(self):
7878
store = dict()
79-
a = self.init_attributes(store, readonly=True)
79+
a = self.init_attributes(store, read_only=True)
8080
store['attrs'] = json.dumps(dict(foo='bar', baz=42)).encode('ascii')
8181
eq(a['foo'], 'bar')
8282
eq(a['baz'], 42)

0 commit comments

Comments
 (0)