Author: mattip <matti.pi...@gmail.com> Branch: Changeset: r77788:0c9994fe9a36 Date: 2015-06-02 21:05 +0300 http://bitbucket.org/pypy/pypy/changeset/0c9994fe9a36/
Log: test, fix to support creating a record array from a different record array diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -1129,6 +1129,16 @@ exc = raises(ValueError, "dtype([('a', '<i8'), ('a', '<f8')])") assert exc.value[0] == 'two fields with the same name' + def test_array_from_record(self): + import numpy as np + a = np.array(('???', -999, -12345678.9), + dtype=[('c', '|S3'), ('a', '<i8'), ('b', '<f8')]) + # Change the order of the keys + b = np.array(a, dtype=[('a', '<i8'), ('b', '<f8'), ('c', '|S3')]) + assert b.base is None + assert b.dtype.fields['a'][1] == 0 + assert b['a'] == -999 + def test_create_from_dict(self): import numpy as np import sys 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 @@ -2363,8 +2363,16 @@ def coerce(self, space, dtype, w_item): from pypy.module.micronumpy.base import W_NDimArray if isinstance(w_item, boxes.W_VoidBox): - return w_item - if w_item is not None: + if dtype == w_item.dtype: + return w_item + else: + # match up the field names + items_w = [None] * len(dtype.fields) + for i in range(len(dtype.fields)): + name = dtype.names[i] + if name in w_item.dtype.names: + items_w[i] = w_item.descr_getitem(space, space.wrap(name)) + elif w_item is not None: if space.isinstance_w(w_item, space.w_tuple): if len(dtype.fields) != space.len_w(w_item): raise OperationError(space.w_ValueError, space.wrap( _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit