Skip to content

Commit 41861b5

Browse files
committed
Fix byte-swapping error on conversion to Object array from big-endian array (byte-swapping was happening twice in that case). This fixes numpy#503.
1 parent e52ea92 commit 41861b5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

numpy/core/src/arrayobject.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -7732,12 +7732,18 @@ PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)
77327732
if (!PyArray_ISNUMBER(mp) && PyErr_Occurred()) return -1;
77337733
}
77347734

7735-
/* If the input or output is STRING, UNICODE, or VOID */
7735+
/* If the input or output is OBJECT, STRING, UNICODE, or VOID */
77367736
/* then getitem and setitem are used for the cast */
77377737
/* and byteswapping is handled by those methods */
77387738

7739-
iswap = PyArray_ISBYTESWAPPED(mp) && !PyArray_ISFLEXIBLE(mp);
7740-
oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out);
7739+
if (PyArray_ISFLEXIBLE(mp) || PyArray_ISOBJECT(mp) || PyArray_ISOBJECT(out) ||
7740+
PyArray_ISFLEXIBLE(out)) {
7741+
iswap = oswap = 0;
7742+
}
7743+
else {
7744+
iswap = PyArray_ISBYTESWAPPED(mp);
7745+
oswap = PyArray_ISBYTESWAPPED(out);
7746+
}
77417747

77427748
return _broadcast_cast(out, mp, castfunc, iswap, oswap);
77437749
}

0 commit comments

Comments
 (0)