[pypy-commit] pypy object-dtype2: test, implement coerce_subtype

mattip noreply at buildbot.pypy.org
Wed Apr 22 11:22:30 CEST 2015


Author: mattip <matti.picus at gmail.com>
Branch: object-dtype2
Changeset: r76863:f49a9dceff61
Date: 2015-04-20 19:57 +0300
http://bitbucket.org/pypy/pypy/changeset/f49a9dceff61/

Log:	test, implement coerce_subtype

diff --git a/pypy/module/micronumpy/test/dummy_module.py b/pypy/module/micronumpy/test/dummy_module.py
--- a/pypy/module/micronumpy/test/dummy_module.py
+++ b/pypy/module/micronumpy/test/dummy_module.py
@@ -20,7 +20,7 @@
 for t in types:
     globals()[t] = dtype(t).type
 
-types = ['bool', 'int', 'float', 'complex', 'str', 'string', 'unicode']
+types = ['bool', 'int', 'float', 'complex', 'str', 'string', 'unicode', 'object']
 for t in types:
     globals()[t + '_'] = dtype(t).type
 del types
diff --git a/pypy/module/micronumpy/test/test_object_arrays.py b/pypy/module/micronumpy/test/test_object_arrays.py
--- a/pypy/module/micronumpy/test/test_object_arrays.py
+++ b/pypy/module/micronumpy/test/test_object_arrays.py
@@ -110,3 +110,19 @@
         c.dtype = a.dtype
         #print c
         assert (c == np.array([(1, 2, 3), (1, 2, 3), (1, 2, 3)], dtype='u4,u4,u4') ).all()
+
+    def test_for_object_scalar_creation(self):
+        import numpy as np
+        a = np.object_()
+        b = np.object_(3)
+        b2 = np.object_(3.0)
+        c = np.object_([4, 5])
+        d = np.object_([None, {}, []])
+        print type(a)
+        assert a is None
+        assert type(b) is int
+        assert type(b2) is float
+        assert type(c) is np.ndarray
+        assert c.dtype == object
+        assert d.dtype == object
+
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
@@ -1648,6 +1648,10 @@
             return w_item
         return boxes.W_ObjectBox(w_item)
 
+    def coerce_subtype(self, space, w_subtype, w_item):
+        # return the item itself
+        return self.unbox(self.box(w_item))
+
     def store(self, arr, i, offset, box):
         self._write(arr.storage, i, offset, self.unbox(box),
                     arr.gcstruct)
@@ -1704,6 +1708,8 @@
             w_obj = self.space.newint(w_obj)
         elif isinstance(w_obj, float):
             w_obj = self.space.newfloat(w_obj)
+        elif w_obj is None:
+            w_obj = self.space.w_None
         else:
             raise oefmt(self.space.w_NotImplementedError,
                 "cannot create object array/scalar from lltype")


More information about the pypy-commit mailing list