Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: numpy-dtype-alt
Changeset: r46702:535f40b5c843
Date: 2011-08-22 02:29 -0500
http://bitbucket.org/pypy/pypy/changeset/535f40b5c843/

Log:    numpy.dtype(None) works, and returns float64, which in turn allows
        simplifying code.

diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -22,7 +22,9 @@
         pass
 
     def descr__new__(space, w_subtype, w_dtype):
-        if space.isinstance_w(w_dtype, space.w_str):
+        if space.is_w(w_dtype, space.w_None):
+            return space.fromcache(W_Float64Dtype)
+        elif space.isinstance_w(w_dtype, space.w_str):
             dtype = space.str_w(w_dtype)
             for alias, dtype_class in dtypes_by_alias:
                 if alias == 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
@@ -2,7 +2,7 @@
 
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import interp2app, unwrap_spec, NoneNotWrapped
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.module.micronumpy import interp_ufuncs, interp_dtype, signature
 from pypy.rlib import jit
@@ -36,9 +36,7 @@
     def add_invalidates(self, other):
         self.invalidates.append(other)
 
-    def descr__new__(space, w_subtype, w_size_or_iterable, 
w_dtype=NoneNotWrapped):
-        if w_dtype is None:
-            w_dtype = space.w_float
+    def descr__new__(space, w_subtype, w_size_or_iterable, w_dtype=None):
         dtype = space.interp_w(interp_dtype.W_Dtype,
             space.call_function(space.gettypefor(interp_dtype.W_Dtype), 
w_dtype)
         )
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
@@ -12,6 +12,7 @@
         assert d.kind == 'b'
         assert dtype('int8').num == 1
         assert dtype(d) is d
+        assert dtype(None) is dtype(float)
 
     def test_dtype_with_types(self):
         from numpy import dtype
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to