Skip to content

Commit b870949

Browse files
committed
greater flexibility for chunks and shape args
1 parent d0d05cc commit b870949

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

zarr/ext.pyx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ cdef class SynchronizedChunk(Chunk):
289289
super(SynchronizedChunk, self).__setitem__(key, value)
290290

291291

292-
cdef normalise_array_selection(item, shape):
292+
def normalise_array_selection(item, shape):
293293
"""Convenience function to normalise a selection within an array with
294294
the given `shape`."""
295295

@@ -318,7 +318,7 @@ cdef normalise_array_selection(item, shape):
318318
raise ValueError('expected indices or slice, found: %r' % item)
319319

320320

321-
cdef normalise_axis_selection(item, l):
321+
def normalise_axis_selection(item, l):
322322
"""Convenience function to normalise a selection within a single axis
323323
of size `l`."""
324324

@@ -349,30 +349,30 @@ cdef normalise_axis_selection(item, l):
349349
raise ValueError('expected integer or slice, found: %r' % item)
350350

351351

352-
cdef get_chunk_range(tuple selection, tuple chunks):
352+
def get_chunk_range(tuple selection, tuple chunks):
353353
"""Convenience function to get a range over all chunk indices,
354354
for iterating over chunks."""
355355
chunk_range = [range(start//l, int(np.ceil(stop/l)))
356356
for (start, stop), l in zip(selection, chunks)]
357357
return chunk_range
358358

359359

360-
cdef normalise_shape(shape):
360+
def normalise_shape(shape):
361361
"""Convenience function to normalise the `shape` argument."""
362-
if isinstance(shape, int):
363-
shape = (shape,)
364-
else:
365-
shape = tuple(shape)
362+
try:
363+
shape = tuple(int(s) for s in shape)
364+
except TypeError:
365+
shape = (int(shape),)
366366
return shape
367367

368368

369-
cdef normalise_chunks(chunks, tuple shape):
369+
def normalise_chunks(chunks, tuple shape):
370370
"""Convenience function to normalise the `chunks` argument for an array
371371
with the given `shape`."""
372-
if isinstance(chunks, int):
373-
chunks = (chunks,)
374-
else:
375-
chunks = tuple(chunks)
372+
try:
373+
chunks = tuple(int(c) for c in chunks)
374+
except TypeError:
375+
chunks = (int(chunks),)
376376
if len(chunks) < len(shape):
377377
# assume chunks across remaining dimensions
378378
chunks += shape[len(chunks):]

0 commit comments

Comments
 (0)