[pypy-svn] pypy numpy-exp: Fixed the exception raises in a bound-error case.

alex_gaynor commits-noreply at bitbucket.org
Thu May 5 03:47:12 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-exp
Changeset: r43904:bf69a764de41
Date: 2011-05-04 21:46 -0400
http://bitbucket.org/pypy/pypy/changeset/bf69a764de41/

Log:	Fixed the exception raises in a bound-error case.

diff --git a/pypy/module/micronumpy/numarray.py b/pypy/module/micronumpy/numarray.py
--- a/pypy/module/micronumpy/numarray.py
+++ b/pypy/module/micronumpy/numarray.py
@@ -260,12 +260,14 @@
 
     @unwrap_spec(item=int)
     def descr_getitem(self, space, item):
+        if item >= self.size:
+            raise operationerrfmt(space.w_IndexError,
+              '%d above array size', item)
         if item < 0:
-            raise operationerrfmt(space.w_TypeError,
+            item += self.size
+        if item < 0:
+            raise operationerrfmt(space.w_IndexError,
               '%d below zero', item)
-        if item >= self.size:
-            raise operationerrfmt(space.w_TypeError,
-              '%d above array size', item)
         return space.wrap(self.storage[item])
 
     @unwrap_spec(item=int, value=float)
diff --git a/pypy/module/micronumpy/test/test_numpy.py b/pypy/module/micronumpy/test/test_numpy.py
--- a/pypy/module/micronumpy/test/test_numpy.py
+++ b/pypy/module/micronumpy/test/test_numpy.py
@@ -23,9 +23,11 @@
     def test_getitem(self):
         from numpy import array
         a = array(range(5))
-        raises(TypeError, "a[5]")
+        raises(IndexError, "a[5]")
         a = a + a
-        raises(TypeError, "a[5]")
+        raises(IndexError, "a[5]")
+        assert a[-1] == 8
+        raises(IndexError, "a[-6]")
 
     def test_add(self):
         from numpy import array


More information about the Pypy-commit mailing list