@@ -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
6163Parameters
@@ -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
220225Parameters
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" )
0 commit comments