Author: Brian Kearns <[email protected]>
Branch:
Changeset: r67661:c07d42e46ab1
Date: 2013-10-28 14:49 -0400
http://bitbucket.org/pypy/pypy/changeset/c07d42e46ab1/
Log: update behavior for this numpy bool indexing special case
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -94,12 +94,11 @@
raise OperationError(space.w_ValueError,
space.wrap("index out of range for array"))
size = loop.count_all_true(idx)
- if size > val.get_size() and val.get_size() > 1:
+ if size > val.get_size() and val.get_size() != 1:
raise OperationError(space.w_ValueError, space.wrap("NumPy boolean
array indexing assignment "
"cannot assign
%d input values to "
- "the %d output
values where the mask is true" % (val.get_size(), size)))
- if val.get_shape() == [0]:
- val.implementation.dtype = self.implementation.dtype
+ "the %d output
values where the mask is true" %
+
(val.get_size(), size)))
loop.setitem_filter(self, idx, val, size)
def _prepare_array_index(self, space, w_index):
diff --git a/pypy/module/micronumpy/test/test_numarray.py
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -2401,7 +2401,7 @@
def test_array_indexing_bool_specialcases(self):
from numpypy import arange, array
a = arange(6)
- exc = raises(ValueError,'a[a < 3] = [1, 2]')
+ exc = raises(ValueError, 'a[a < 3] = [1, 2]')
assert exc.value[0].find('cannot assign') >= 0
b = arange(4).reshape(2, 2) + 10
a[a < 4] = b
@@ -2415,8 +2415,9 @@
a[a > 3] = array([15])
assert (a == [0, 1, 2, 3, 15, 15]).all()
a = arange(6).reshape(3, 2)
- a[a & 1 == 1] = [] # here, Numpy sticks garbage into the array
- assert a.shape == (3, 2)
+ exc = raises(ValueError, 'a[a & 1 == 1] = []')
+ assert exc.value[0].find('cannot assign') >= 0
+ assert (a == [[0, 1], [2, 3], [4, 5]]).all()
def test_copy_kwarg(self):
from numpypy import array
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit