Author: mattip <[email protected]>
Branch: numpypy-problems
Changeset: r58184:0fcfcdb4f777
Date: 2012-10-16 23:39 +0200
http://bitbucket.org/pypy/pypy/changeset/0fcfcdb4f777/

Log:    fix to_str, clean up debug cruft; now passes test_stringarray

diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -275,6 +275,9 @@
             arr.storage[i] = arg[i]
         return W_StringBox(arr, 0, arr.dtype)
 
+    def convert_to(self, dtype):
+        return self.arr
+
 class W_UnicodeBox(W_CharacterBox):
     def descr__new__unicode_box(space, w_subtype, w_arg):
         from pypy.module.micronumpy.interp_dtype import new_unicode_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
@@ -684,7 +684,6 @@
     arr = W_NDimArray.from_shape(shape, dtype, order=order)
     arr_iter = arr.create_iter(arr.get_shape())
     for w_elem in elems_w:
-        print 'setting',arr_iter.offset,'to',w_elem
         arr_iter.setitem(dtype.coerce(space, w_elem))
         arr_iter.next()
     return arr
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
@@ -2259,7 +2259,7 @@
         assert a[0] == 'abc'
         assert a[1] == 'defg'
         assert a[2] == 'ab'
-        assert repr(a) == "array(['abc', 'defg', ab'])"
+        assert repr(a) == "array(['abc', 'defg', 'ab'])"
 
        
 class AppTestPyPy(BaseNumpyAppTest):
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1478,28 +1478,23 @@
 
     def store(self, arr, i, offset, box):
         assert isinstance(box, interp_boxes.W_StringBox)
-        for k in range(min(self.size-i, box.arr.size-offset)):
+        for k in range(min(self.size, box.arr.size-offset)):
             arr.storage[k + i] = box.arr.storage[k + offset]
 
     def read(self, arr, i, offset, dtype=None):
         if dtype is None:
             dtype = arr.dtype
         return interp_boxes.W_StringBox(arr, i + offset, dtype)
-        #print 'read',arr, arr.dtype
-        #xxx
-        #builder = StringBuilder()
-        #i = 0
-        #while i < self.size:
-        #    assert isinstance(arr.storage[i], str)
-        #    builder.append(arr.storage[i])
-        #    i += 1
-        #return builder.build()
+
     def to_str(self, item):
         builder = StringBuilder()
         assert isinstance(item, interp_boxes.W_StringBox)
-        i = 0
-        while i < self.size:
+        i = item.ofs
+        end = i+self.size
+        while i < end:
             assert isinstance(item.arr.storage[i], str)
+            if item.arr.storage[i] == '\x00':
+                break
             builder.append(item.arr.storage[i])
             i += 1
         return builder.build()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to