[pypy-commit] pypy default: fix numpy scalar descr_float

bdkearns noreply at buildbot.pypy.org
Thu Feb 20 22:31:25 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r69226:5c0b56c4704a
Date: 2014-02-20 16:18 -0500
http://bitbucket.org/pypy/pypy/changeset/5c0b56c4704a/

Log:	fix numpy scalar descr_float

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
@@ -170,8 +170,7 @@
 
     def descr_float(self, space):
         box = self.convert_to(space, W_Float64Box._get_dtype(space))
-        assert isinstance(box, PrimitiveBox)
-        return space.wrap(box.value)
+        return space.float(box.item(space))
 
     def descr_oct(self, space):
         return space.oct(self.descr_int(space))
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
@@ -2204,6 +2204,12 @@
                 assert exc.value.message == "don't know how to convert " \
                                             "scalar number to %s" % op
 
+    def test__float__(self):
+        import numpy as np
+        assert float(np.array(1.5)) == 1.5
+        exc = raises(TypeError, "float(np.array([1.5, 2.5]))")
+        assert exc.value[0] == 'only length-1 arrays can be converted to Python scalars'
+
     def test__reduce__(self):
         from numpypy import array, dtype
         from cPickle import loads, dumps


More information about the pypy-commit mailing list