Author: Matti Picus <[email protected]>
Branch: ndarray-subtype
Changeset: r65385:0447d303da95
Date: 2013-07-14 00:28 +0300
http://bitbucket.org/pypy/pypy/changeset/0447d303da95/

Log:    move and more correctly define an array(object) test, raise
        NotImplementedError where this fails

diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -538,7 +538,13 @@
         return current_guess
     if current_guess is complex_type:
         return complex_type
-    return interp_dtype.get_dtype_cache(space).w_float64dtype
+    if space.isinstance_w(w_obj, space.w_float):
+        return interp_dtype.get_dtype_cache(space).w_float64dtype
+    elif space.isinstance_w(w_obj, space.w_slice):
+        return long_dtype
+    raise operationerrfmt(space.w_NotImplementedError,
+        'unable to create dtype from objects, ' '"%T" instance not supported',
+        w_obj)
 
 
 def ufunc_dtype_caller(space, ufunc_name, op_name, argcount, comparison_func,
diff --git a/pypy/module/micronumpy/test/test_dtypes.py 
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -976,3 +976,16 @@
         assert a[0] == 1
         assert (a + a)[1] == 4
 
+class AppTestObjectDtypes(BaseNumpyAppTest):
+    def test_scalar_from_object(self):
+        from numpypy import array
+        class Polynomial(object):
+            pass
+        try:
+            a = array(Polynomial())
+            assert a.shape == ()
+        except NotImplementedError, e:
+            if e.message.find('unable to create dtype from objects')>=0:
+                skip('creating ojbect dtype not supported yet')
+
+
diff --git a/pypy/module/micronumpy/test/test_subtype.py 
b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -50,17 +50,6 @@
         b[0]=100
         assert a[0,0] == 100
 
-    def test_ndarray_from_iterable(self):
-        from numpypy import array
-        class Polynomial(object):
-            def __init__(self, coef):
-                self.coef = coef
-            def __iter__(self):
-                return iter(self.coef)
-            def __len__(self):
-                return len(self.coef)
-        a = array(Polynomial([1, 2, 3]))
-
     def test_subtype_view(self):
         from numpypy import ndarray, array
         class matrix(ndarray):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to