[pypy-commit] pypy default: provide copy for numpy scalars

bdkearns noreply at buildbot.pypy.org
Mon Nov 11 04:49:24 CET 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r67944:a6bcf5d26ccd
Date: 2013-11-10 22:41 -0500
http://bitbucket.org/pypy/pypy/changeset/a6bcf5d26ccd/

Log:	provide copy for numpy scalars

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
@@ -289,6 +289,9 @@
     def descr_get_ndim(self, space):
         return space.wrap(0)
 
+    def descr_copy(self, space):
+        return self.convert_to(self.get_dtype(space))
+
 class W_BoolBox(W_GenericBox, PrimitiveBox):
     descr__new__, _get_dtype, descr_reduce = new_dtype_getter("bool")
 
@@ -538,6 +541,7 @@
     astype = interp2app(W_GenericBox.descr_astype),
     view = interp2app(W_GenericBox.descr_view),
     squeeze = interp2app(W_GenericBox.descr_self),
+    copy = interp2app(W_GenericBox.descr_copy),
 
     dtype = GetSetProperty(W_GenericBox.descr_get_dtype),
     itemsize = GetSetProperty(W_GenericBox.descr_get_itemsize),
diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -65,6 +65,14 @@
         assert type(a) is np.int32
         assert a == 1
 
+    def test_copy(self):
+        import numpy as np
+        a = np.int32(2)
+        b = a.copy()
+        assert type(b) is type(a)
+        assert b == a
+        assert b is not a
+
     def test_squeeze(self):
         import numpy as np
         assert np.True_.squeeze() is np.True_


More information about the pypy-commit mailing list