Commits

Justin Peel committed 21b2605

change array repr and str to format ints and bools correctly. still need to show dtype.

  • Participants
  • Parent commits 52e1f87
  • Branches numpy-dtype

Comments (0)

Files changed (2)

File pypy/module/micronumpy/interp_numarray.py

             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

File pypy/module/micronumpy/test/test_numarray.py

         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
         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