1. Tobias Oberstein
  2. pypy

Commits

Brian Kearns  committed c16f3a1

fix setitem using array scalars also

  • Participants
  • Parent commits f5dbd42
  • Branches default

Comments (0)

Files changed (2)

File pypy/module/micronumpy/interp_numarray.py

View file
  • Ignore whitespace
         self.implementation.setitem_index(space, index_list, w_value)
 
     def descr_setitem(self, space, w_idx, w_value):
-        if isinstance(w_idx, W_NDimArray) and w_idx.get_dtype().is_bool_type():
+        if isinstance(w_idx, W_NDimArray) and w_idx.get_dtype().is_bool_type() \
+                and len(w_idx.get_shape()) > 0:
             self.setitem_filter(space, w_idx, convert_to_array(space, w_value))
             return
         try:

File pypy/module/micronumpy/test/test_numarray.py

View file
  • Ignore whitespace
                       [7, 8, 9]])
         assert (a[np.array(0)] == a[0]).all()
         assert (a[np.array(1)] == a[1]).all()
+        assert (a[np.array(True)] == a[1]).all()
+        assert (a[np.array(False)] == a[0]).all()
         exc = raises(IndexError, "a[np.array(1.1)]")
         assert exc.value.message == 'arrays used as indices must be of ' \
                                     'integer (or boolean) type'
-        assert (a[np.array(True)] == a[1]).all()
-        assert (a[np.array(False)] == a[0]).all()
+
+        a[np.array(1)] = a[2]
+        assert a[1][1] == 8
+        a[np.array(True)] = a[0]
+        assert a[1][1] == 2
+        exc = raises(IndexError, "a[np.array(1.1)] = a[2]")
+        assert exc.value.message == 'arrays used as indices must be of ' \
+                                    'integer (or boolean) type'
 
     def test_bool_array_index(self):
         from numpypy import arange, array