Author: Brian Kearns <[email protected]>
Branch: numpy-refactor
Changeset: r69479:efbc3fbb15c3
Date: 2014-02-26 17:43 -0500
http://bitbucket.org/pypy/pypy/changeset/efbc3fbb15c3/
Log: fix slicing message for array scalars
diff --git a/pypy/module/micronumpy/concrete.py
b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -189,7 +189,9 @@
space.isinstance_w(w_item, space.w_list)):
raise ArrayArgumentException
return self._lookup_by_index(space, view_w)
- if shape_len > 1:
+ if shape_len == 0:
+ raise oefmt(space.w_IndexError, "0-d arrays can't be indexed")
+ elif shape_len > 1:
raise IndexError
idx = support.index_w(space, w_idx)
return self._lookup_by_index(space, [space.wrap(idx)])
@@ -204,7 +206,7 @@
"field named %s not found" % idx))
return RecordChunk(idx)
if len(self.get_shape()) == 0:
- raise oefmt(space.w_IndexError, "0-d arrays can't be indexed")
+ raise oefmt(space.w_ValueError, "cannot slice a 0-d array")
if (space.isinstance_w(w_idx, space.w_int) or
space.isinstance_w(w_idx, space.w_slice)):
return Chunks([Chunk(*space.decode_index4(w_idx,
self.get_shape()[0]))])
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
@@ -657,6 +657,9 @@
def test_setslice_array(self):
from numpypy import array
+ a = array(5)
+ exc = raises(ValueError, "a[:] = 4")
+ assert exc.value[0] == "cannot slice a 0-d array"
a = array(range(5))
b = array(range(2))
a[1:4:2] = b
@@ -1350,6 +1353,9 @@
def test_getslice(self):
from numpypy import array
+ a = array(5)
+ exc = raises(ValueError, "a[:]")
+ assert exc.value[0] == "cannot slice a 0-d array"
a = array(range(5))
s = a[1:5]
assert len(s) == 4
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit