[pypy-commit] pypy default: test, fix extra quotes in astype() for object to str ndarray conversion
mattip
noreply at buildbot.pypy.org
Thu Oct 29 05:20:51 EDT 2015
Author: mattip <matti.picus at gmail.com>
Branch:
Changeset: r80475:cdb5f895892c
Date: 2015-10-29 09:53 +1100
http://bitbucket.org/pypy/pypy/changeset/cdb5f895892c/
Log: test, fix extra quotes in astype() for object to str ndarray
conversion
diff --git a/pypy/module/micronumpy/test/test_object_arrays.py b/pypy/module/micronumpy/test/test_object_arrays.py
--- a/pypy/module/micronumpy/test/test_object_arrays.py
+++ b/pypy/module/micronumpy/test/test_object_arrays.py
@@ -172,6 +172,7 @@
a = np.array([b'a' * 100], dtype='O')
assert 'a' * 100 in str(a)
b = a.astype('S')
+ assert b.dtype == 'S100'
assert 'a' * 100 in str(b)
a = np.array([123], dtype='U')
assert a[0] == u'123'
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1891,6 +1891,12 @@
return self.BoxType(w_obj)
def str_format(self, box, add_quotes=True):
+ if not add_quotes:
+ as_str = self.space.str_w(self.space.repr(self.unbox(box)))
+ as_strl = len(as_str) - 1
+ if as_strl>1 and as_str[0] == "'" and as_str[as_strl] == "'":
+ as_str = as_str[1:as_strl]
+ return as_str
return self.space.str_w(self.space.repr(self.unbox(box)))
def runpack_str(self, space, s, native):
More information about the pypy-commit
mailing list