[pypy-commit] pypy numpypy-problems: implement StringArray methods, add failing test

mattip noreply at buildbot.pypy.org
Thu Sep 27 01:16:20 CEST 2012


Author: mattip <matti.picus at gmail.com>
Branch: numpypy-problems
Changeset: r57622:4c5d7dc7f7d9
Date: 2012-09-27 01:15 +0200
http://bitbucket.org/pypy/pypy/changeset/4c5d7dc7f7d9/

Log:	implement StringArray methods, add failing test

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
@@ -228,7 +228,7 @@
         except KeyError:
             raise OperationError(space.w_IndexError,
                                  space.wrap("Field %s does not exist" % item))
-        return dtype.itemtype.read(self.arr, self.ofs, ofs, dtype)
+        return space.wrap(dtype.itemtype.read(self.arr, self.ofs, ofs, dtype))
 
     @unwrap_spec(item=str)
     def descr_setitem(self, space, item, w_value):
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
@@ -2244,6 +2244,11 @@
         assert a[0]['x'] == 'a'
         assert a[1]['y'] == 1
 
+    def test_stringarray(self):
+        from _numpypy import array
+        a = array(['abc'])
+        assert str(a) == "['abc']"
+        assert a.dtype == '|S3'
        
 class AppTestPyPy(BaseNumpyAppTest):
     def setup_class(cls):
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
@@ -907,6 +907,20 @@
 class StringType(BaseType, BaseStringType):
     T = lltype.Char
 
+    def coerce(self, space, dtype, w_item):
+        if space.isinstance_w(w_item, space.w_str):
+            return space.unwrap(w_item)
+        print 'w_item',type(w_item)
+        xxx
+
+    def store(self, arr, i, offset, box):
+        assert isinstance(box, str)
+        for k in range(min(self.size-i, len(box)-offset)):
+            arr.storage[k + i] = box[k + offset]
+
+    def read(self, arr, i, offset, dtype=None):
+        return arr.storage[i+offset]
+
 class VoidType(BaseType, BaseStringType):
     T = lltype.Char
 


More information about the pypy-commit mailing list