Author: Justin Peel <[email protected]>
Branch:
Changeset: r51444:db7b9b0aa08d
Date: 2012-01-17 22:13 -0700
http://bitbucket.org/pypy/pypy/changeset/db7b9b0aa08d/
Log: fix a bug in to_str for ndim=1, size=1 arrays. also affected any
multi-dim array where the last dimension is 1. tests included.
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
@@ -919,14 +919,14 @@
if size < 1:
builder.append('[]')
return
- elif size == 1:
- builder.append(dtype.itemtype.str_format(self.getitem(0)))
- return
if size > 1000:
# Once this goes True it does not go back to False for recursive
# calls
use_ellipsis = True
ndims = len(self.shape)
+ if ndims == 0:
+ builder.append(dtype.itemtype.str_format(self.getitem(0)))
+ return
i = 0
builder.append('[')
if ndims > 1:
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
@@ -1441,9 +1441,11 @@
assert repr(a) == "array(0.0)"
a = array(0.2)
assert repr(a) == "array(0.2)"
+ a = array([2])
+ assert repr(a) == "array([2])"
def test_repr_multi(self):
- from _numpypy import arange, zeros
+ from _numpypy import arange, zeros, array
a = zeros((3, 4))
assert repr(a) == '''array([[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
@@ -1466,6 +1468,9 @@
[498, 999],
[499, 1000],
[500, 1001]])'''
+ a = arange(2).reshape((2,1))
+ assert repr(a) == '''array([[0],
+ [1]])'''
def test_repr_slice(self):
from _numpypy import array, zeros
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit