10000 BUG: bool(scalar) is not the same as scalar.astype(bool) · Issue #9847 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: bool(scalar) is not the same as scalar.astype(bool) #9847

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

Closed
eric-wieser opened this issue Oct 11, 2017 · 1 comment
Closed

BUG: bool(scalar) is not the same as scalar.astype(bool) #9847

eric-wieser opened this issue Oct 11, 2017 · 1 comment
Labels

Comments

@eric-wieser
Copy link
Member
eric-wieser commented Oct 11, 2017

At least, with the void type:

>>> v1 = np.array(b'', (np.void,1))[()]
>>> v2 = np.array(b'', (np.void,2))[()]
>>> bool(v1), bool(v2)
(False, False)  # reasonable, meaning all null
>>> v1.astype(bool)
False # ok
>>> v1.astype(bool)
ValueError: setting an array element with a sequence.  # uh oh

And the string type:

>>> s = np.array('0')[()]
>>> bool(s)
True
>>> s.astype(bool)
False  # actually bool(int(s))
eric-wieser added a commit to eric-wieser/numpy that referenced this issue Oct 14, 2017
Caused by void scalars decaying to 1d uint8 arrays before casting - `getitem` is dangerous for intermediate results

Works towards numpy#9847
eric-wieser added a commit to eric-wieser/numpy that referenced this issue Oct 15, 2017
Caused by string values being cast to an int first and then a bool, ie arr.astype(int).astype(bool).
This causes crashes on non-numeric strings, and only accepts strings of 0 as false.

Fixes numpy#9847
@eric-wieser
Copy link
Member Author

Now that void scalars are fixed, closing in favor of #9875, which is a better summary of the can of worms which strings are.

theodoregoetz pushed a commit to theodoregoetz/numpy that referenced this issue Oct 23, 2017
Caused by void scalars decaying to 1d uint8 arrays before casting - `getitem` is dangerous for intermediate results

Works towards numpy#9847
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant
0