Commits

mattip committed 4c5d7dc

implement StringArray methods, add failing test

  • Participants
  • Parent commits b9a4275
  • Branches numpypy-problems

Comments (0)

Files changed (3)

File pypy/module/micronumpy/interp_boxes.py

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

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

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

File pypy/module/micronumpy/types.py

 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