Skip to content

Commit 41063ef

Browse files
authored
Merge pull request numpy#25948 from seberg/improve-error
MAINT: Introduce NPY_FEATURE_VERSION_STRING and report it in error
2 parents 80a21e7 + 3c1fcb3 commit 41063ef

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

numpy/_core/code_generators/generate_numpy_api.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@
111111
}
112112
PyArray_RUNTIME_VERSION = (int)PyArray_GetNDArrayCFeatureVersion();
113113
if (NPY_FEATURE_VERSION > PyArray_RUNTIME_VERSION) {
114-
PyErr_Format(PyExc_RuntimeError, "module compiled against "\
115-
"API version 0x%%x but this version of numpy is 0x%%x . "\
116-
"Check the section C-API incompatibility at the "\
117-
"Troubleshooting ImportError section at "\
118-
"https://numpy.org/devdocs/user/troubleshooting-importerror.html"\
119-
"#c-api-incompatibility "\
120-
"for indications on how to solve this problem .", \
114+
PyErr_Format(PyExc_RuntimeError,
115+
"module was compiled against NumPy C-API version 0x%%x "
116+
"(NumPy " NPY_FEATURE_VERSION_STRING ") "
117+
"but the running NumPy has C-API version 0x%%x. "
118+
"Check the section C-API incompatibility at the "
119+
"Troubleshooting ImportError section at "
120+
"https://numpy.org/devdocs/user/troubleshooting-importerror.html"
121+
"#c-api-incompatibility "
122+
"for indications on how to solve this problem.",
121123
(int)NPY_FEATURE_VERSION, PyArray_RUNTIME_VERSION);
122124
return -1;
123125
}

numpy/_core/include/numpy/numpyconfig.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,37 @@
132132
#warning "Requested NumPy target lower than supported NumPy 1.15."
133133
#endif
134134

135+
/*
136+
* We define a human readable translation to the Python version of NumPy
137+
* for error messages (and also to allow grepping the binaries for conda).
138+
*/
139+
#if NPY_FEATURE_VERSION == NPY_1_7_API_VERSION
140+
#define NPY_FEATURE_VERSION_STRING "1.7"
141+
#elif NPY_FEATURE_VERSION == NPY_1_8_API_VERSION
142+
#define NPY_FEATURE_VERSION_STRING "1.8"
143+
#elif NPY_FEATURE_VERSION == NPY_1_9_API_VERSION
144+
#define NPY_FEATURE_VERSION_STRING "1.9"
145+
#elif NPY_FEATURE_VERSION == NPY_1_10_API_VERSION /* also 1.11, 1.12 */
146+
#define NPY_FEATURE_VERSION_STRING "1.10"
147+
#elif NPY_FEATURE_VERSION == NPY_1_13_API_VERSION
148+
#define NPY_FEATURE_VERSION_STRING "1.13"
149+
#elif NPY_FEATURE_VERSION == NPY_1_14_API_VERSION /* also 1.15 */
150+
#define NPY_FEATURE_VERSION_STRING "1.14"
151+
#elif NPY_FEATURE_VERSION == NPY_1_16_API_VERSION /* also 1.17, 1.18, 1.19 */
152+
#define NPY_FEATURE_VERSION_STRING "1.16"
153+
#elif NPY_FEATURE_VERSION == NPY_1_20_API_VERSION /* also 1.21 */
154+
#define NPY_FEATURE_VERSION_STRING "1.20"
155+
#elif NPY_FEATURE_VERSION == NPY_1_22_API_VERSION
156+
#define NPY_FEATURE_VERSION_STRING "1.22"
157+
#elif NPY_FEATURE_VERSION == NPY_1_23_API_VERSION /* also 1.24 */
158+
#define NPY_FEATURE_VERSION_STRING "1.23"
159+
#elif NPY_FEATURE_VERSION == NPY_1_25_API_VERSION
160+
#define NPY_FEATURE_VERSION_STRING "1.25"
161+
#elif NPY_FEATURE_VERSION == NPY_2_0_API_VERSION
162+
#define NPY_FEATURE_VERSION_STRING "2.0"
163+
#else
164+
#error "Missing version string define for new NumPy version."
165+
#endif
166+
135167

136168
#endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_NUMPYCONFIG_H_ */

0 commit comments

Comments
 (0)