[pypy-commit] pypy default: fix ndarray.astype(S0)

bdkearns noreply at buildbot.pypy.org
Mon Feb 24 02:04:06 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r69319:f2ff6d660efd
Date: 2014-02-23 19:17 -0500
http://bitbucket.org/pypy/pypy/changeset/f2ff6d660efd/

Log:	fix ndarray.astype(S0)

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
@@ -572,6 +572,10 @@
         if new_dtype.num == NPY.VOID:
             raise oefmt(space.w_NotImplementedError,
                 "%s.astype(%s) not implemented yet", cur_dtype.name, new_dtype.name)
+        if new_dtype.num == NPY.STRING and new_dtype.size == 0:
+            if cur_dtype.num == NPY.STRING:
+                new_dtype = interp_dtype.variable_dtype(space,
+                    'S' + str(cur_dtype.size))
         impl = self.implementation
         if isinstance(impl, scalar.Scalar):
             return W_NDimArray.new_scalar(space, new_dtype, impl.value)
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
@@ -2102,6 +2102,7 @@
         assert a[2] == 3.0
 
         a = array('123')
+        assert a.astype('S0').dtype == 'S3'
         assert a.astype('i8') == 123
         a = array('abcdefgh')
         exc = raises(ValueError, a.astype, 'i8')


More information about the pypy-commit mailing list