Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r67696:8bbe7e215208 Date: 2013-10-29 13:00 -0400 http://bitbucket.org/pypy/pypy/changeset/8bbe7e215208/
Log: fixes for some numpy exceptions diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py --- a/pypy/module/micronumpy/arrayimpl/concrete.py +++ b/pypy/module/micronumpy/arrayimpl/concrete.py @@ -203,7 +203,7 @@ dtype = self.dtype if not dtype.is_record_type() or idx not in dtype.fields: raise OperationError(space.w_ValueError, space.wrap( - "field named %s not defined" % idx)) + "field named %s not found" % idx)) return RecordChunk(idx) if (space.isinstance_w(w_idx, space.w_int) or space.isinstance_w(w_idx, space.w_slice)): 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 @@ -201,8 +201,6 @@ return self.implementation.descr_getitem(space, self, w_idx) except ArrayArgumentException: return self.getitem_array_int(space, w_idx) - except OperationError: - raise OperationError(space.w_IndexError, space.wrap("wrong index")) def getitem(self, space, index_list): return self.implementation.getitem_index(space, index_list) diff --git a/pypy/module/micronumpy/support.py b/pypy/module/micronumpy/support.py --- a/pypy/module/micronumpy/support.py +++ b/pypy/module/micronumpy/support.py @@ -5,7 +5,11 @@ try: return space.int_w(space.index(w_obj)) except OperationError: - return space.int_w(space.int(w_obj)) + try: + return space.int_w(space.int(w_obj)) + except OperationError: + raise OperationError(space.w_IndexError, space.wrap( + "cannot convert index to integer")) @jit.unroll_safe def product(s): 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 @@ -525,8 +525,10 @@ from numpypy import arange a = arange(10) - raises(IndexError, "a[ErrorIndex()] == 0") - raises(IndexError, "a[ErrorInt()] == 0") + exc = raises(IndexError, "a[ErrorIndex()] == 0") + assert exc.value.message == 'cannot convert index to integer' + exc = raises(IndexError, "a[ErrorInt()] == 0") + assert exc.value.message == 'cannot convert index to integer' def test_setslice_array(self): from numpypy import array @@ -2960,6 +2962,8 @@ a[0, 0] = 500 assert (a[0, 0, 0] == 500).all() assert a[0, 0, 0].shape == (10,) + exc = raises(ValueError, "a[0, 0]['z']") + assert exc.value.message == 'field named z not found' def test_subarray_multiple_rows(self): import numpypy as np _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit