-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: fix inconsistency with np.array(['']) being truthy #5967
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
Sounds good, but what about " \x00" strings? So I think the fix is right but should be moved further down. I.e. to include all spaces which are followed by only "\x00" and nothing else. Which is our rule for giving back things out of the array. |
On the other hand, I find the whitespace rule odd, python seems to behave different? |
Of course, in python, empty string falsey and any other string truthy. I don't know why numpy considers whitespace strings falsey aswell, but assumed there must be a good reason since it is explicitly checked? I'm happy to fix that too but it seems like a much bigger logical change. |
Yeah, it is. Maybe we could be made a FutureWarning, but should probably write the list before that. Considering the inconsistencies, I think it might be a real option to change, but then I tend to think we should weed out this stuff ;). It is likely difficult to find out why it is as it is, it isn't implausible to me that python itself changed the definition at some point. Though one could argue the fix converts some False's to True's that in the end we might prefer to be False ;), but it is more the other way around probably :). |
OK, I will remove the explicit length check and look for all trailing nulls. Can you confirm the tests in the last commit are the desired behaviour for now? (They will be failing currently of course) |
Fortran pads strings with whitespace rather than nulls. The strange
truthiness probably somehow derives from that; even though strings don't
have truth value in F.
|
+1 to FutureWarning from me, though yeah, should email list
|
To email list and FutureWarning is for if/when the behaviour for whitespace string is changed to match python's behaviour, not for this change, right? Is anything else needed for this PR? |
Code seems good to me the " \0 \0" being False thing seems good to me as well. |
@homu r=seberg
|
📌 Commit 8749a9a has been approved by |
BUG: fix inconsistency with np.array(['']) being truthy ``` a = np.array([0]) b = np.array([None]) c = np.array(['']) d = np.array([' ']) ``` Why should we have this inconsistency: ``` >>> bool(a) False >>> bool(b) False >>> bool(c) True >>> bool(d) False ```
☀️ Test successful - status |
Why should we have this inconsistency: