Author: Justin Peel <[email protected]>
Branch: numpy-dtype
Changeset: r46234:21b2605606ce
Date: 2011-08-03 01:13 -0600
http://bitbucket.org/pypy/pypy/changeset/21b2605606ce/
Log: change array repr and str to format ints and bools correctly. still
need to show dtype.
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
@@ -200,19 +200,24 @@
return self.descr_mul(space, w_other)
def _getnums(self, comma):
+ kind = self.find_dtype().kind
+ if kind == 'f':
+ format_func = float2string
+ else:
+ format_func = str
if self.find_size() > 1000:
nums = [
- float2string(self.eval(index))
+ format_func(self.eval(index))
for index in range(3)
]
nums.append("..." + "," * comma)
nums.extend([
- float2string(self.eval(index))
+ format_func(self.eval(index))
for index in range(self.find_size() - 3, self.find_size())
])
else:
nums = [
- float2string(self.eval(index))
+ format_func(self.eval(index))
for index in range(self.find_size())
]
return nums
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
@@ -56,6 +56,10 @@
assert repr(a) == "array([0.0, 1.0, 2.0, 3.0, 4.0])"
a = zeros(1001)
assert repr(a) == "array([0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0])"
+ a = array(range(5), 'l')
+ assert repr(a) == "array([0, 1, 2, 3, 4])"
+ a = array([True, False, True, False], '?')
+ assert repr(a) == "array([True, False, True, False])"
def test_repr_slice(self):
from numpy import array, zeros
@@ -73,6 +77,10 @@
assert str((2*a)[:]) == "[0.0 2.0 4.0 6.0 8.0]"
a = zeros(1001)
assert str(a) == "[0.0 0.0 0.0 ..., 0.0 0.0 0.0]"
+ a = array(range(5), 'l')
+ assert str(a) == "[0 1 2 3 4]"
+ a = array([True, False, True, False], '?')
+ assert str(a) == "[True False True False]"
def test_str_slice(self):
from numpy import array, zeros
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit