[pypy-commit] pypy default: fix array init with char dtype
bdkearns
noreply at buildbot.pypy.org
Tue Feb 25 10:06:26 CET 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r69411:0f6a27d08000
Date: 2014-02-25 04:05 -0500
http://bitbucket.org/pypy/pypy/changeset/0f6a27d08000/
Log: fix array init with char dtype
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
@@ -1448,9 +1448,10 @@
# scalars and strings w/o __array__ method
isstr = space.isinstance_w(w_object, space.w_str)
if not issequence_w(space, w_object) or isstr:
- if dtype is None or (dtype.is_str_or_unicode() and dtype.elsize < 1):
- dtype = interp_ufuncs.find_dtype_for_scalar(space, w_object)
- return W_NDimArray.new_scalar(space, dtype, w_object)
+ if dtype is None or dtype.char != NPY.CHARLTR:
+ if dtype is None or (dtype.is_str_or_unicode() and dtype.elsize < 1):
+ dtype = interp_ufuncs.find_dtype_for_scalar(space, w_object)
+ return W_NDimArray.new_scalar(space, dtype, w_object)
if space.is_none(w_order):
order = 'C'
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
@@ -1697,16 +1697,12 @@
assert exc.value[0] == "data-type must not be 0-sized"
assert a.view('S4') == '\x03'
a = array('abc1', dtype='c')
- import sys
- if '__pypy__' in sys.builtin_module_names:
- raises(ValueError, a.view, 'S4')
- raises(ValueError, a.view, [('a', 'i2'), ('b', 'i2')])
- else:
- assert a.view('S4') == 'abc1'
- b = a.view([('a', 'i2'), ('b', 'i2')])
- assert b.shape == (1,)
- assert b[0][0] == 25185
- assert b[0][1] == 12643
+ assert (a == ['a', 'b', 'c', '1']).all()
+ assert a.view('S4') == 'abc1'
+ b = a.view([('a', 'i2'), ('b', 'i2')])
+ assert b.shape == (1,)
+ assert b[0][0] == 25185
+ assert b[0][1] == 12643
a = array([(1, 2)], dtype=[('a', 'int64'), ('b', 'int64')])[0]
assert a.shape == ()
assert a.view('S16') == '\x01' + '\x00' * 7 + '\x02'
More information about the pypy-commit
mailing list