[pypy-commit] pypy str-dtype-improvement: test, fix concatenate two str arrays
mattip
noreply at buildbot.pypy.org
Wed Mar 20 21:16:20 CET 2013
Author: Matti Picus <matti.picus at gmail.com>
Branch: str-dtype-improvement
Changeset: r62556:ee54a9e3ac5a
Date: 2013-03-20 11:44 -0700
http://bitbucket.org/pypy/pypy/changeset/ee54a9e3ac5a/
Log: test, fix concatenate two str arrays
diff --git a/pypy/module/micronumpy/interp_arrayops.py b/pypy/module/micronumpy/interp_arrayops.py
--- a/pypy/module/micronumpy/interp_arrayops.py
+++ b/pypy/module/micronumpy/interp_arrayops.py
@@ -133,9 +133,6 @@
raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
if _axis < 0 or len(shape) <= _axis:
raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
- if dtype is None:
- raise OperationError(space.w_TypeError, space.wrap(
- 'invalid type promotion'))
res = W_NDimArray.from_shape(shape, dtype, 'C')
chunks = [Chunk(0, i, 1, i) for i in shape]
axis_start = 0
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -441,12 +441,14 @@
return dt2
if dt1.is_str_or_unicode():
if dt2.num == 18:
- size = max(dt2.itemtype.get_element_size(),
- dt1.itemtype.get_element_size())
- return interp_dtype.new_string_dtype(space, size)
- size = max(dt2.itemtype.get_element_size(),
- dt1.itemtype.get_element_size())
- return interp_dtype.new_unicode_dtype(space, size)
+ if dt2.itemtype.get_element_size() >= \
+ dt1.itemtype.get_element_size():
+ return dt2
+ return dt1
+ if dt2.itemtype.get_element_size() >= \
+ dt1.itemtype.get_element_size():
+ return dt2
+ return dt1
return dt2
else:
# increase to the next signed type
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
@@ -1484,6 +1484,9 @@
assert str(a.dtype) == '|S3'
a = concatenate((array([]), array(['abc'])))
assert a[0] == 'abc'
+ a = concatenate((['abcdef'], ['abc']))
+ assert a[0] == 'abcdef'
+ assert str(a.dtype) == '|S6'
def test_record_concatenate(self):
# only an exact match can succeed
More information about the pypy-commit
mailing list