@@ -54,8 +54,10 @@ def normalize_integer_selection(dim_sel, dim_len):
54
54
return dim_sel
55
55
56
56
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
+ )
59
61
"""A mapping from chunk to output array for a single dimension.
60
62
61
63
Parameters
@@ -149,7 +151,8 @@ def __iter__(self):
149
151
dim_chunk_sel_stop = self .stop - dim_offset
150
152
151
153
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 )
153
156
dim_out_sel = slice (dim_out_offset , dim_out_offset + dim_chunk_nitems )
154
157
155
158
yield ChunkDimProjection (dim_chunk_ix , dim_chunk_sel , dim_out_sel )
@@ -211,11 +214,13 @@ def ensure_tuple(v):
211
214
return v
212
215
213
216
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.
219
224
220
225
Parameters
221
226
----------
@@ -264,7 +269,8 @@ def __init__(self, selection, array):
264
269
265
270
# setup per-dimension indexers
266
271
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 ):
268
274
269
275
if is_integer (dim_sel ):
270
276
dim_indexer = IntDimIndexer (dim_sel , dim_len , dim_chunk_len )
@@ -273,8 +279,9 @@ def __init__(self, selection, array):
273
279
dim_indexer = SliceDimIndexer (dim_sel , dim_len , dim_chunk_len )
274
280
275
281
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 )))
278
285
279
286
dim_indexers .append (dim_indexer )
280
287
@@ -300,7 +307,8 @@ def __init__(self, dim_sel, dim_len, dim_chunk_len):
300
307
301
308
# check number of dimensions
302
309
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' )
304
312
305
313
# check shape
306
314
if dim_sel .shape [0 ] != dim_len :
@@ -392,7 +400,8 @@ def __init__(self, dim_sel, dim_len, dim_chunk_len, wraparound=True, boundscheck
392
400
# ensure 1d array
393
401
dim_sel = np .asanyarray (dim_sel )
394
402
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' )
396
405
397
406
# handle wraparound
398
407
if wraparound :
@@ -409,7 +418,8 @@ def __init__(self, dim_sel, dim_len, dim_chunk_len, wraparound=True, boundscheck
409
418
self .nitems = len (dim_sel )
410
419
411
420
# 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
413
423
dim_sel_chunk = dim_sel // dim_chunk_len
414
424
415
425
# determine order of indices
@@ -520,7 +530,8 @@ def __init__(self, selection, array):
520
530
521
531
# setup per-dimension indexers
522
532
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 ):
524
535
525
536
if is_integer (dim_sel ):
526
537
dim_indexer = IntDimIndexer (dim_sel , dim_len , dim_chunk_len )
@@ -535,8 +546,9 @@ def __init__(self, selection, array):
535
546
dim_indexer = BoolArrayDimIndexer (dim_sel , dim_len , dim_chunk_len )
536
547
537
548
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}'
540
552
.format (type (dim_sel )))
541
553
542
554
dim_indexers .append (dim_indexer )
@@ -563,9 +575,10 @@ def __iter__(self):
563
575
# handle advanced indexing arrays orthogonally
564
576
if self .is_advanced :
565
577
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.
569
582
chunk_selection = ix_ (chunk_selection , self .array ._chunks )
570
583
571
584
# special case for non-monotonic indices
@@ -623,8 +636,9 @@ def __init__(self, selection, array):
623
636
624
637
# validation
625
638
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 ))
628
642
629
643
# handle wraparound, boundscheck
630
644
for dim_sel , dim_len in zip (selection , array .shape ):
@@ -764,8 +778,8 @@ def check_fields(fields, dtype):
764
778
return dtype
765
779
# check type
766
780
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 )))
769
783
if fields :
770
784
if dtype .names is None :
771
785
raise IndexError ("invalid 'fields' argument, array does not have any fields" )
0 commit comments