[pypy-commit] pypy default: fix segfault on np.arr.astype(record)

bdkearns noreply at buildbot.pypy.org
Sun Feb 23 22:45:59 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r69302:5ec998bf16a1
Date: 2014-02-23 16:40 -0500
http://bitbucket.org/pypy/pypy/changeset/5ec998bf16a1/

Log:	fix segfault on np.arr.astype(record)

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
@@ -569,7 +569,7 @@
         cur_dtype = self.get_dtype()
         new_dtype = space.interp_w(interp_dtype.W_Dtype,
             space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
-        if new_dtype.shape:
+        if new_dtype.num == NPY.VOID:
             raise oefmt(space.w_NotImplementedError,
                 "%s.astype(%s) not implemented yet", cur_dtype.name, new_dtype.name)
         impl = self.implementation
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
@@ -3287,6 +3287,17 @@
         assert arr[1]['y']['x'] == 0.0
         assert arr[1]['x'] == 15
 
+    def test_count_nonzero(self):
+        import numpy as np
+        import sys
+        d = [('f0', 'i4'), ('f1', 'i4', 2)]
+        arr = np.array([0, 1])
+        if '__pypy__' not in sys.builtin_module_names:
+            arr = arr.astype(d)[:1]
+            assert np.count_nonzero(arr) == 0
+        else:
+            raises(NotImplementedError, "arr.astype(d)")
+
     def test_string_record(self):
         from numpypy import dtype, array
 


More information about the pypy-commit mailing list