-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
nonzero on arrays of characters with whitespace #9462
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
Comments
Would be good to hear your thoughts on this one too, @eric-wieser, if you have time. |
I was about to ask about what you just reported in #9479 anyway, so there's obviously something screwy going on here |
Seems to be by design: static npy_bool
STRING_nonzero (char *ip, PyArrayObject *ap)
{
int len = PyArray_DESCR(ap)->elsize;
int i;
npy_bool nonz = NPY_FALSE;
npy_bool seen_null = NPY_FALSE;
for (i = 0; i < len; i++) {
if (*ip == '\0') {
seen_null = NPY_TRUE;
}
else if (seen_null || !Py_STRING_ISSPACE(*ip)) {
nonz = NPY_TRUE;
break;
}
ip++;
}
return nonz;
} |
See #9848 |
Seems you have opened issue ( #9875 ), which more generally captures the problem here. Should we close this out and follow along on that issue instead? |
Duplicate of #9875, please reopen if I misunderstood |
It seems that whitespace in a character array is treated as if it is zero. An example of this is shown below with details about the environment. This seems to match up with how character arrays work. Still this seems a bit surprising from a Python perspective. Am trying to understand if this is intentional and also if there is an builtin element-wise operator that we can use to reproduce this behavior.
Code snippet:
Environment:
The text was updated successfully, but these errors were encountered: