-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: Chain exceptions to give better error messages for invalid PEP3118 format strings #11119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Where would be a good place for |
numpy/core/src/multiarray/buffer.c
Outdated
PyErr_Format(PyExc_ValueError, | ||
"'%s' is not a valid PEP 3118 buffer format string", buf); | ||
PyArray_ChainExceptionsCause(exc, val, tb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the prototype for PyArray_ChainExceptionsCause
needs to be in an include file, it is defined in arrayobject.c
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which include file would you recommend? npy_compat.h
?
We might want to reconsider the layout of the include files at some point. |
03d26f5
to
1515b7e
Compare
…18 format strings Sample console output: ``` In [1]: from ctypes import c_wchar In [2]: x = c_wchar * 3 In [3]: np.array(x()) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) ~\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\_internal.py in _dtype_from_pep3118(spec) 486 --> 487 dtype, align = __dtype_from_pep3118(stream, is_subdtype=False) 488 return dtype ~\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\_internal.py in __dtype_from_pep3118(stream, is_subdtype) 558 else: --> 559 raise ValueError("Unknown PEP 3118 data type specifier %r" % stream.s) 560 ValueError: Unknown PEP 3118 data type specifier 'u' The above exception was the direct cause of the following exception: ValueError Traceback (most recent call last) <ipython-input-3-f8a17df3aa24> in <module>() ----> 1 np.array(x()) ValueError: '<u' is not a valid PEP 3118 buffer format string ```
1515b7e
to
b6e03a4
Compare
Moved to np_compat3k.h and prefixed with |
Thanks Eric |
Sample console output: