summaryrefslogtreecommitdiff
path: root/numpy/core/src/arrayobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r--numpy/core/src/arrayobject.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 199189b8f..e16e92ec8 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -7732,12 +7732,18 @@ PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)
if (!PyArray_ISNUMBER(mp) && PyErr_Occurred()) return -1;
}
- /* If the input or output is STRING, UNICODE, or VOID */
+ /* If the input or output is OBJECT, STRING, UNICODE, or VOID */
/* then getitem and setitem are used for the cast */
/* and byteswapping is handled by those methods */
- iswap = PyArray_ISBYTESWAPPED(mp) && !PyArray_ISFLEXIBLE(mp);
- oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out);
+ if (PyArray_ISFLEXIBLE(mp) || PyArray_ISOBJECT(mp) || PyArray_ISOBJECT(out) ||
+ PyArray_ISFLEXIBLE(out)) {
+ iswap = oswap = 0;
+ }
+ else {
+ iswap = PyArray_ISBYTESWAPPED(mp);
+ oswap = PyArray_ISBYTESWAPPED(out);
+ }
return _broadcast_cast(out, mp, castfunc, iswap, oswap);
}