From a590b4dc7a7a527c5df4e2c67d6506d8b6a26d9a Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Wed, 25 Sep 2024 22:52:27 -0700 Subject: [PATCH] Set Python error if NumPy init failed If NumPy initialization failed, raise a proper Python exception when we try to call functions that require NumPy. --- modules/kernel/pyext/IMP_kernel.numpy.i | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/kernel/pyext/IMP_kernel.numpy.i b/modules/kernel/pyext/IMP_kernel.numpy.i index c8370899d4..3efc81ee85 100644 --- a/modules/kernel/pyext/IMP_kernel.numpy.i +++ b/modules/kernel/pyext/IMP_kernel.numpy.i @@ -6,6 +6,8 @@ PyObject *_get_floats_data_numpy(PyObject *m_pyobj, unsigned sz, double *data) { #if IMP_KERNEL_HAS_NUMPY if (numpy_import_retval != 0) { + PyErr_SetString(PyExc_ImportError, + "IMP's NumPy support did not initialize correctly"); return NULL; } @@ -41,6 +43,8 @@ PyObject *_get_ints_data_numpy(PyObject *m_pyobj, unsigned sz, int *data) { #if IMP_KERNEL_HAS_NUMPY if (numpy_import_retval != 0) { + PyErr_SetString(PyExc_ImportError, + "IMP's NumPy support did not initialize correctly"); return NULL; } @@ -108,6 +112,8 @@ PyObject *_get_spheres_data_numpy(PyObject *m_pyobj, unsigned sz, { #if IMP_KERNEL_HAS_NUMPY if (numpy_import_retval != 0) { + PyErr_SetString(PyExc_ImportError, + "IMP's NumPy support did not initialize correctly"); return NULL; }