Skip to content

Commit 0fc6a1e

Browse files
Fix indexing for scalar numpy values (#967) (#974)
* Fix indexing for scalar numpy values (#967) * Fix linting errors * Remove whitespace from GH editor * Fix `W391 blank line at end of file` Co-authored-by: Josh Moore <j.a.moore@dundee.ac.uk> Co-authored-by: jmoore <josh@glencoesoftware.com>
1 parent 6b5db73 commit 0fc6a1e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

docs/release.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ Release notes
66
Unreleased
77
----------
88

9+
.. _release_2.11.1:
10+
11+
2.11.1
12+
------
913

1014
Bug fixes
1115
~~~~~~~~~
1216

17+
* Fix bug where indexing with a scalar numpy value returned a single-value array.
18+
By :user:`Ben Jeffery <benjeffery>` :issue:`967`.
19+
1320
* Removed `clobber` argument from `normalize_store_arg`. This enables to change
1421
data within a opened consolidated group using mode `"r+"` (i.e region write).
1522
By :user:`Tobias Kölling <d70-t>` :issue:`975`.

zarr/indexing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ def is_integer_list(x):
3434

3535

3636
def is_integer_array(x, ndim=None):
37-
t = hasattr(x, 'shape') and hasattr(x, 'dtype') and x.dtype.kind in 'ui'
37+
t = not np.isscalar(x) and \
38+
hasattr(x, 'shape') and \
39+
hasattr(x, 'dtype') and \
40+
x.dtype.kind in 'ui'
3841
if ndim is not None:
3942
t = t and len(x.shape) == ndim
4043
return t

zarr/tests/test_indexing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy
12
import numpy as np
23
import pytest
34
from numpy.testing import assert_array_equal
@@ -1442,3 +1443,11 @@ def test_slice_selection_uints():
14421443
idx = np.uint64(3)
14431444
slice_sel = make_slice_selection((idx,))
14441445
assert arr[slice_sel].shape == (1, 6)
1446+
1447+
1448+
def test_numpy_int_indexing():
1449+
a = np.arange(1050)
1450+
z = zarr.create(shape=1050, chunks=100, dtype=a.dtype)
1451+
z[:] = a
1452+
assert a[42] == z[42]
1453+
assert a[numpy.int64(42)] == z[numpy.int64(42)]

0 commit comments

Comments
 (0)