Skip to content

Commit f015b5f

Browse files
fujiisoupmrocklin
authored andcommitted
Support indexing with np.int (dask#2719)
* Support indexing with np.int * Update changelog.rst
1 parent a4a5c1b commit f015b5f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

dask/array/slicing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def normalize_index(idx, shape):
751751
idx = replace_ellipsis(len(shape), idx)
752752
n_sliced_dims = 0
753753
for i in idx:
754-
if hasattr(i, 'ndim'):
754+
if hasattr(i, 'ndim') and i.ndim >= 1:
755755
n_sliced_dims += i.ndim
756756
elif i is None:
757757
continue

dask/array/tests/test_array_core.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,13 +1626,27 @@ def test_slice_with_floats():
16261626
d[[1, 1.5]]
16271627

16281628

1629-
def test_slice_with_uint():
1629+
def test_slice_with_integer_types():
16301630
x = np.arange(10)
16311631
dx = da.from_array(x, chunks=5)
16321632
inds = np.array([0, 3, 6], dtype='u8')
16331633
assert_eq(dx[inds], x[inds])
16341634
assert_eq(dx[inds.astype('u4')], x[inds.astype('u4')])
16351635

1636+
inds = np.array([0, 3, 6], dtype=np.int64)
1637+
assert_eq(dx[inds], x[inds])
1638+
assert_eq(dx[inds.astype('u4')], x[inds.astype('u4')])
1639+
1640+
1641+
def test_index_with_integer_types():
1642+
x = np.arange(10)
1643+
dx = da.from_array(x, chunks=5)
1644+
inds = int(3)
1645+
assert_eq(dx[inds], x[inds])
1646+
1647+
inds = np.int64(3)
1648+
assert_eq(dx[inds], x[inds])
1649+
16361650

16371651
def test_vindex_basic():
16381652
x = np.arange(56).reshape((7, 8))

docs/source/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Changelog
77
Array
88
+++++
99

10-
-
10+
- Indexing with np.int (:pr:`2718`)
1111

1212

1313
DataFrame

0 commit comments

Comments
 (0)