Skip to content

Commit d7ad9fb

Browse files
authored
Always use tuples for multidimensional indexing (#376)
* Always use `tuple`s for multidimensional indexing NumPy 1.15.0 deprecates the use of sequences in `ndarray` selection for sequences other than `tuple`s. We have a few cases where we are using `list`s instead as they are mutable. Thus are easier to build up and change. However passing `list`s into `ndarray` selection will cause this `FutureWarning` to be emitted (and will eventually result in an error). To fix this simply, just convert these `list`s to `tuple`s after we are done changing their contents, but before we use them with `ndarray`s. This works just as well on older versions of NumPy. Avoids the `FutureWarning` in NumPy 1.15.0+. Not to mention this will continue to work on future versions of NumPy, which may change this warning into an error. * Note use of `tuple`s for slicing NumPy `ndarrays`
1 parent bf2b672 commit d7ad9fb

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Bug fixes
3838
* Ensure ``DictStore`` contains only ``bytes`` to facilitate comparisons and protect against writes.
3939
By :user:`John Kirkham <jakirkham>`, :issue:`350`
4040

41+
* Always use a ``tuple`` when indexing a NumPy ``ndarray``.
42+
By :user:`John Kirkham <jakirkham>`, :issue:`376`
43+
4144
Maintenance
4245
~~~~~~~~~~~
4346

zarr/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ def _set_selection(self, indexer, value, fields=None):
15311531
item = [slice(None)] * self.ndim
15321532
for a in indexer.drop_axes:
15331533
item[a] = np.newaxis
1534+
item = tuple(item)
15341535
chunk_value = chunk_value[item]
15351536

15361537
# put data

zarr/indexing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ def oindex_set(a, selection, value):
513513
value_selection = [slice(None)] * len(a.shape)
514514
for i in drop_axes:
515515
value_selection[i] = np.newaxis
516+
value_selection = tuple(value_selection)
516517
value = value[value_selection]
517518
a[selection] = value
518519

0 commit comments

Comments
 (0)