Skip to content

Commit 97354f3

Browse files
committed
tidy
1 parent 2eabfe8 commit 97354f3

File tree

7 files changed

+62
-40
lines changed

7 files changed

+62
-40
lines changed

zarr/attrs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ def put(self, d):
113113
self._write_op(self._put_nosync, d)
114114

115115
def _put_nosync(self, d):
116-
s = json.dumps(d, indent=4, sort_keys=True, ensure_ascii=True, separators=(',', ': '))
116+
s = json.dumps(d, indent=4, sort_keys=True, ensure_ascii=True,
117+
separators=(',', ': '))
117118
self.store[self.key] = s.encode('ascii')
118119
if self.cache:
119120
self._cached_asdict = d
120121

122+
# noinspection PyMethodOverriding
121123
def update(self, *args, **kwargs):
122124
"""Update the values of several attributes in a single operation."""
123125
self._write_op(self._update_nosync, *args, **kwargs)

zarr/convenience.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def open(store, mode='a', **kwargs):
5454
>>> zr = zarr.open(store, mode='r') # open existing array read-only
5555
>>> zr
5656
<zarr.core.Array (100,) int32 read-only>
57-
>>> gw = zarr.open(store, mode='w') # open new group, overwriting any previous data
57+
>>> gw = zarr.open(store, mode='w') # open new group, overwriting previous data
5858
>>> gw
5959
<zarr.hierarchy.Group '/'>
6060
>>> ga = zarr.open(store, mode='a') # open existing group for reading and writing
@@ -97,8 +97,8 @@ def open(store, mode='a', **kwargs):
9797

9898

9999
def save_array(store, arr, **kwargs):
100-
"""Convenience function to save a NumPy array to the local file system, following a similar
101-
API to the NumPy save() function.
100+
"""Convenience function to save a NumPy array to the local file system, following a
101+
similar API to the NumPy save() function.
102102
103103
Parameters
104104
----------
@@ -152,7 +152,8 @@ def save_group(store, *args, **kwargs):
152152
153153
Examples
154154
--------
155-
Save several arrays to a directory on the file system (uses a :class:`DirectoryStore`)::
155+
Save several arrays to a directory on the file system (uses a
156+
:class:`DirectoryStore`):
156157
157158
>>> import zarr
158159
>>> import numpy as np
@@ -333,17 +334,18 @@ def load(store):
333334
Returns
334335
-------
335336
out
336-
If the store contains an array, out will be a numpy array. If the store contains a group,
337-
out will be a dict-like object where keys are array names and values are numpy arrays.
337+
If the store contains an array, out will be a numpy array. If the store contains
338+
a group, out will be a dict-like object where keys are array names and values
339+
are numpy arrays.
338340
339341
See Also
340342
--------
341343
save, savez
342344
343345
Notes
344346
-----
345-
If loading data from a group of arrays, data will not be immediately loaded into memory.
346-
Rather, arrays will be loaded into memory as they are requested.
347+
If loading data from a group of arrays, data will not be immediately loaded into
348+
memory. Rather, arrays will be loaded into memory as they are requested.
347349
348350
"""
349351
# handle polymorphic store arg

zarr/creation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ def create(shape, chunks=True, dtype=None, compressor='default',
8080
Create an array with different some different configuration options::
8181
8282
>>> from numcodecs import Blosc
83+
>>> compressor = Blosc(cname='zstd', clevel=1, shuffle=Blosc.BITSHUFFLE)
8384
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='i1', order='F',
84-
... compressor=Blosc(cname='zstd', clevel=1, shuffle=Blosc.BITSHUFFLE))
85+
... compressor=compressor)
8586
>>> z
8687
<zarr.core.Array (10000, 10000) int8>
8788
88-
To create an array with object dtype requires a filter that can handle Python object encoding,
89-
e.g., `MsgPack` or `Pickle` from `numcodecs`::
89+
To create an array with object dtype requires a filter that can handle Python object
90+
encoding, e.g., `MsgPack` or `Pickle` from `numcodecs`::
9091
9192
>>> from numcodecs import MsgPack
9293
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype=object,

zarr/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ def err_too_many_indices(selection, shape):
6161

6262

6363
def err_vindex_invalid_selection(selection):
64-
raise IndexError('unsupported selection type for vectorized indexing; only coordinate '
65-
'selection (tuple of integer arrays) and mask selection (single '
66-
'Boolean array) are supported; got {!r}'.format(selection))
64+
raise IndexError('unsupported selection type for vectorized indexing; only '
65+
'coordinate selection (tuple of integer arrays) and mask selection '
66+
'(single Boolean array) are supported; got {!r}'.format(selection))

zarr/hierarchy.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ def require_groups(self, *names):
708708
"""Convenience method to require multiple groups in a single call."""
709709
return tuple(self.require_group(name) for name in names)
710710

711+
# noinspection PyIncorrectDocstring
711712
def create_dataset(self, name, **kwargs):
712713
"""Create an array.
713714
@@ -977,7 +978,8 @@ def move(self, source, dest):
977978
dest = self._item_path(dest)
978979

979980
# Check that source exists.
980-
if not (contains_array(self._store, source) or contains_group(self._store, source)):
981+
if not (contains_array(self._store, source) or
982+
contains_group(self._store, source)):
981983
raise ValueError('The source, "%s", does not exist.' % source)
982984
if contains_array(self._store, dest) or contains_group(self._store, dest):
983985
raise ValueError('The dest, "%s", already exists.' % dest)

zarr/indexing.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ def normalize_integer_selection(dim_sel, dim_len):
5454
return dim_sel
5555

5656

57-
ChunkDimProjection = collections.namedtuple('ChunkDimProjection',
58-
('dim_chunk_ix', 'dim_chunk_sel', 'dim_out_sel'))
57+
ChunkDimProjection = collections.namedtuple(
58+
'ChunkDimProjection',
59+
('dim_chunk_ix', 'dim_chunk_sel', 'dim_out_sel')
60+
)
5961
"""A mapping from chunk to output array for a single dimension.
6062
6163
Parameters
@@ -149,7 +151,8 @@ def __iter__(self):
149151
dim_chunk_sel_stop = self.stop - dim_offset
150152

151153
dim_chunk_sel = slice(dim_chunk_sel_start, dim_chunk_sel_stop, self.step)
152-
dim_chunk_nitems = ceildiv((dim_chunk_sel_stop - dim_chunk_sel_start), self.step)
154+
dim_chunk_nitems = ceildiv((dim_chunk_sel_stop - dim_chunk_sel_start),
155+
self.step)
153156
dim_out_sel = slice(dim_out_offset, dim_out_offset + dim_chunk_nitems)
154157

155158
yield ChunkDimProjection(dim_chunk_ix, dim_chunk_sel, dim_out_sel)
@@ -211,11 +214,13 @@ def ensure_tuple(v):
211214
return v
212215

213216

214-
ChunkProjection = collections.namedtuple('ChunkProjection',
215-
('chunk_coords', 'chunk_selection', 'out_selection'))
216-
"""A mapping of items from chunk to output array. Can be used to extract items from the chunk
217-
array for loading into an output array. Can also be used to extract items from a value array for
218-
setting/updating in a chunk array.
217+
ChunkProjection = collections.namedtuple(
218+
'ChunkProjection',
219+
('chunk_coords', 'chunk_selection', 'out_selection')
220+
)
221+
"""A mapping of items from chunk to output array. Can be used to extract items from the
222+
chunk array for loading into an output array. Can also be used to extract items from a
223+
value array for setting/updating in a chunk array.
219224
220225
Parameters
221226
----------
@@ -264,7 +269,8 @@ def __init__(self, selection, array):
264269

265270
# setup per-dimension indexers
266271
dim_indexers = []
267-
for dim_sel, dim_len, dim_chunk_len in zip(selection, array._shape, array._chunks):
272+
for dim_sel, dim_len, dim_chunk_len in \
273+
zip(selection, array._shape, array._chunks):
268274

269275
if is_integer(dim_sel):
270276
dim_indexer = IntDimIndexer(dim_sel, dim_len, dim_chunk_len)
@@ -273,8 +279,9 @@ def __init__(self, selection, array):
273279
dim_indexer = SliceDimIndexer(dim_sel, dim_len, dim_chunk_len)
274280

275281
else:
276-
raise IndexError('unsupported selection item for basic indexing; expected integer '
277-
'or slice, got {!r}'.format(type(dim_sel)))
282+
raise IndexError('unsupported selection item for basic indexing; '
283+
'expected integer or slice, got {!r}'
284+
.format(type(dim_sel)))
278285

279286
dim_indexers.append(dim_indexer)
280287

@@ -300,7 +307,8 @@ def __init__(self, dim_sel, dim_len, dim_chunk_len):
300307

301308
# check number of dimensions
302309
if not is_bool_array(dim_sel, 1):
303-
raise IndexError('Boolean arrays in an orthogonal selection must 1-dimensional only')
310+
raise IndexError('Boolean arrays in an orthogonal selection must '
311+
'be 1-dimensional only')
304312

305313
# check shape
306314
if dim_sel.shape[0] != dim_len:
@@ -392,7 +400,8 @@ def __init__(self, dim_sel, dim_len, dim_chunk_len, wraparound=True, boundscheck
392400
# ensure 1d array
393401
dim_sel = np.asanyarray(dim_sel)
394402
if not is_integer_array(dim_sel, 1):
395-
raise IndexError('integer arrays in an orthogonal selection must be 1-dimensional only')
403+
raise IndexError('integer arrays in an orthogonal selection must be '
404+
'1-dimensional only')
396405

397406
# handle wraparound
398407
if wraparound:
@@ -409,7 +418,8 @@ def __init__(self, dim_sel, dim_len, dim_chunk_len, wraparound=True, boundscheck
409418
self.nitems = len(dim_sel)
410419

411420
# determine which chunk is needed for each selection item
412-
# note: for dense integer selections, the division operation here is the bottleneck
421+
# note: for dense integer selections, the division operation here is the
422+
# bottleneck
413423
dim_sel_chunk = dim_sel // dim_chunk_len
414424

415425
# determine order of indices
@@ -520,7 +530,8 @@ def __init__(self, selection, array):
520530

521531
# setup per-dimension indexers
522532
dim_indexers = []
523-
for dim_sel, dim_len, dim_chunk_len in zip(selection, array._shape, array._chunks):
533+
for dim_sel, dim_len, dim_chunk_len in \
534+
zip(selection, array._shape, array._chunks):
524535

525536
if is_integer(dim_sel):
526537
dim_indexer = IntDimIndexer(dim_sel, dim_len, dim_chunk_len)
@@ -535,8 +546,9 @@ def __init__(self, selection, array):
535546
dim_indexer = BoolArrayDimIndexer(dim_sel, dim_len, dim_chunk_len)
536547

537548
else:
538-
raise IndexError('unsupported selection item for orthogonal indexing; expected '
539-
'integer, slice, integer array or Boolean array, got {!r}'
549+
raise IndexError('unsupported selection item for orthogonal indexing; '
550+
'expected integer, slice, integer array or Boolean '
551+
'array, got {!r}'
540552
.format(type(dim_sel)))
541553

542554
dim_indexers.append(dim_indexer)
@@ -563,9 +575,10 @@ def __iter__(self):
563575
# handle advanced indexing arrays orthogonally
564576
if self.is_advanced:
565577

566-
# numpy doesn't support orthogonal indexing directly as yet, so need to work
567-
# around via np.ix_. Also np.ix_ does not support a mixture of arrays and slices
568-
# or integers, so need to convert slices and integers into ranges.
578+
# N.B., numpy doesn't support orthogonal indexing directly as yet,
579+
# so need to work around via np.ix_. Also np.ix_ does not support a
580+
# mixture of arrays and slices or integers, so need to convert slices
581+
# and integers into ranges.
569582
chunk_selection = ix_(chunk_selection, self.array._chunks)
570583

571584
# special case for non-monotonic indices
@@ -623,8 +636,9 @@ def __init__(self, selection, array):
623636

624637
# validation
625638
if not is_coordinate_selection(selection, array):
626-
raise IndexError('invalid coordinate selection; expected one integer (coordinate) '
627-
'array per dimension of the target array, got {!r}'.format(selection))
639+
raise IndexError('invalid coordinate selection; expected one integer '
640+
'(coordinate) array per dimension of the target array, '
641+
'got {!r}'.format(selection))
628642

629643
# handle wraparound, boundscheck
630644
for dim_sel, dim_len in zip(selection, array.shape):
@@ -764,8 +778,8 @@ def check_fields(fields, dtype):
764778
return dtype
765779
# check type
766780
if not isinstance(fields, (str, list, tuple)):
767-
raise IndexError("'fields' argument must be a string or list of strings; found {!r}"
768-
.format(type(fields)))
781+
raise IndexError("'fields' argument must be a string or list of strings; found "
782+
"{!r}".format(type(fields)))
769783
if fields:
770784
if dtype.names is None:
771785
raise IndexError("invalid 'fields' argument, array does not have any fields")

zarr/meta.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def decode_fill_value(v, dtype):
139139
else:
140140
return np.array(v, dtype=dtype)[()]
141141
elif dtype.kind in 'SV':
142+
# noinspection PyBroadException
142143
try:
143144
v = base64.standard_b64decode(v)
144145
v = np.array(v, dtype=dtype)[()]

0 commit comments

Comments
 (0)