diff options
author | kngwyu <yuji.kngw.80s.revive@gmail.com> | 2018-10-09 16:38:51 +0900 |
---|---|---|
committer | kngwyu <yuji.kngw.80s.revive@gmail.com> | 2018-10-14 18:26:10 +0900 |
commit | 7131b696d10f143f9755ce6f7b5d5c03ecbc7459 (patch) | |
tree | 2323fdde53af0b1a71ac1e36e3eccae0b1894a24 /numpy/core | |
parent | 86a7acc8582923604fac849bb19f0b08efc0a91a (diff) | |
download | numpy-7131b696d10f143f9755ce6f7b5d5c03ecbc7459.tar.gz |
MAINT: Clarify the error message for resize failure
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/shape.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c index 3ac71e285..30820737e 100644 --- a/numpy/core/src/multiarray/shape.c +++ b/numpy/core/src/multiarray/shape.c @@ -89,11 +89,19 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck, return NULL; } + if (PyArray_BASE(self) != NULL + || (((PyArrayObject_fields *)self)->weakreflist != NULL)) { + PyErr_SetString(PyExc_ValueError, + "cannot resize an array that " + "references or is referenced\n" + "by another array in this way. Use the np.resize function."); + return NULL; + } if (refcheck) { #ifdef PYPY_VERSION PyErr_SetString(PyExc_ValueError, "cannot resize an array with refcheck=True on PyPy.\n" - "Use the resize function or refcheck=False"); + "Use the np.resize function or refcheck=False"); return NULL; #else refcnt = PyArray_REFCOUNT(self); @@ -102,13 +110,12 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck, else { refcnt = 1; } - if ((refcnt > 2) - || (PyArray_BASE(self) != NULL) - || (((PyArrayObject_fields *)self)->weakreflist != NULL)) { + if (refcnt > 2) { PyErr_SetString(PyExc_ValueError, "cannot resize an array that " "references or is referenced\n" - "by another array in this way. Use the resize function"); + "by another array in this way.\n" + "Use the np.resize function or refcheck=False"); return NULL; } |