diff options
| author | Mircea Akos Bruma <akos@debian-gnu-linux-vm.localdomain> | 2019-04-13 13:14:03 +0200 |
|---|---|---|
| committer | Mircea Akos Bruma <akos@debian-gnu-linux-vm.localdomain> | 2019-04-17 11:11:33 +0200 |
| commit | df34770bde8ff4aa4834b9baf161e83beacfefb8 (patch) | |
| tree | a949ce5809dcf6fadac0e5e7c4555912de4511ec /numpy/core/src | |
| parent | 8f31f95910d27da75941bbbbde7ef1ecec9b0f74 (diff) | |
| download | numpy-df34770bde8ff4aa4834b9baf161e83beacfefb8.tar.gz | |
ENH: improve memory error message by adding shape and data type (#13225)
Diffstat (limited to 'numpy/core/src')
| -rw-r--r-- | numpy/core/src/multiarray/ctors.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 42cd31069..9677a13d9 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -1072,8 +1072,30 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd, data = npy_alloc_cache(nbytes); } if (data == NULL) { - PyErr_NoMemory(); - goto fail; + static PyObject *exc_type = NULL; + + npy_cache_import( + "numpy.core._exceptions", "_ArrayMemoryError", + &exc_type); + if (exc_type == NULL) { + return NULL; + } + + PyObject *shape = PyArray_IntTupleFromIntp(fa->nd,fa->dimensions); + if (shape == NULL) { + return NULL; + } + + /* produce an error object */ + PyObject *exc_value = PyTuple_Pack(2, shape, descr); + Py_DECREF(shape); + if (exc_value == NULL){ + return NULL; + } + PyErr_SetObject(exc_type, exc_value); + Py_DECREF(exc_value); + return NULL; + } fa->flags |= NPY_ARRAY_OWNDATA; |
