Author: Sergey Matyunin <[email protected]>
Branch: fix_indexing_by_numpy_int
Changeset: r83046:889015cbbfed
Date: 2016-03-13 22:33 +0100
http://bitbucket.org/pypy/pypy/changeset/889015cbbfed/
Log: Fixed indexing by numpy.int
diff --git a/pypy/module/micronumpy/ndarray.py
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -267,6 +267,11 @@
"interpreted as a valid boolean index")
elif isinstance(w_idx, boxes.W_GenericBox):
w_ret = self.getitem_array_int(space, w_idx)
+
+ if isinstance(w_idx, boxes.W_IntegerBox):
+ # if w_idx is integer then getitem_array_int must contain a
single value and we must return it.
+ # Get 0-th element of the w_ret.
+ w_ret = w_ret.implementation.descr_getitem(space, self,
space.wrap(0))
else:
try:
w_ret = self.implementation.descr_getitem(space, self, w_idx)
diff --git a/pypy/module/micronumpy/test/test_ndarray.py
b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -3397,6 +3397,22 @@
a.itemset(1, 2, 100)
assert a[1, 2] == 100
+ def test_index_int64(self):
+ import numpy as np
+ res = np.array([10, 20, 30])[np.int64(1)]
+
+ assert isinstance(res, np.int64)
+ assert not isinstance(res, np.ndarray)
+ assert res == 20
+
+ def test_index_int32(self):
+ import numpy as np
+ res = np.array([10, 20, 30])[np.int32(0)]
+
+ assert isinstance(res, np.int64)
+ assert not isinstance(res, np.ndarray)
+ assert res == 10
+
def test_index(self):
import numpy as np
a = np.array([1], np.uint16)
@@ -3408,6 +3424,7 @@
assert exc.value.message == 'only integer arrays with one element
' \
'can be converted to an index'
+
def test_int_array_index(self):
from numpy import array
assert (array([])[[]] == []).all()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit