-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
ENH: PyArray_FromInterface checks descr if typestr is np.void #5519
Conversation
da38fb0
to
5d3026e
Compare
There is still a hole in the ability of numpy to fully reconstruct an array, including its dtype, using
but if you really want it, you can get it:
|
5d3026e
to
69db6f5
Compare
Added a little logic to |
#if defined(NPY_PY3K) | ||
/* Allow unicode type strings */ | ||
if (PyUnicode_Check(typestr2)) { | ||
tmp = PyUnicode_AsASCIIString(typestr2); |
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 tmp can be NULL, assuming that the string cannot be converted to ascii. I'm not sure what the policy for this codec is.
Looks like there may be some conflicts with #5371, so lets get that in first. You are welcome to merge it :0 |
@jaimefrio Needs rebase. |
69db6f5
to
56c0e21
Compare
Rebased it is. Still need to figure how to handle that potential failure in the ASCII conversion... |
56c0e21
to
af92638
Compare
When the 'typestr' member of the __array_interface__ dictionary defines a np.void dtype, check the 'descr' member, and if it is a valid dtype description and it is not the default one, use it to construct the dtype for the array to return. This fixes numpy#5081, as as_strided no longer has to worry about changing the dtype of the return.
af92638
to
0808ae8
Compare
I think I have now taken care of the possible error: if we cannot convert to ASCII, then it isn't the default |
return 0; | ||
} | ||
tuple = PyList_GET_ITEM(descr, 0); | ||
if (!(PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2)) { |
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.
I like the way this condition is expressed better than the one above ;)
ENH: PyArray_FromInterface checks descr if typestr is np.void
LGTM, thanks Jaime. |
When the 'typestr' member of the array_interface dictionary defines
a np.void dtype, check the 'descr' member, and if it is a valid dtype
description and it is not the default one, use it to construct the
dtype for the array to return.
This fixes #5081, as as_strided no longer has to worry about changing
the dtype of the return.