[pypy-commit] pypy numpy-newbyteorder: fix newbyteorder() not changing the itemtype
bdkearns
noreply at buildbot.pypy.org
Fri Nov 8 02:09:59 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch: numpy-newbyteorder
Changeset: r67880:f0af04bbb177
Date: 2013-11-07 19:33 -0500
http://bitbucket.org/pypy/pypy/changeset/f0af04bbb177/
Log: fix newbyteorder() not changing the itemtype
diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -313,7 +313,8 @@
endian = NPY_OPPBYTE if self.is_native() else NPY_NATBYTE
elif newendian != NPY_IGNORE:
endian = newendian
- return W_Dtype(self.itemtype, self.num, self.kind, self.name, self.char, self.w_box_type, endian)
+ itemtype = self.itemtype.__class__(endian in (NPY_NATIVE, NPY_NATBYTE))
+ return W_Dtype(itemtype, self.num, self.kind, self.name, self.char, self.w_box_type, endian)
def dtype_from_list(space, w_lst):
lst_w = space.listview(w_lst)
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
@@ -304,6 +304,13 @@
exc = raises(ValueError, dt.newbyteorder, 'XX')
assert exc.value[0] == 'XX is an unrecognized byteorder'
+ for t in [np.int_, np.float_]:
+ dt1 = np.dtype(t)
+ dt2 = dt1.newbyteorder()
+ s1 = np.array(123, dtype=dt1).tostring()
+ s2 = np.array(123, dtype=dt2).byteswap().tostring()
+ assert s1 == s2
+
class AppTestTypes(BaseAppTestDtypes):
def test_abstract_types(self):
import numpypy as numpy
More information about the pypy-commit
mailing list