Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Converting char to bool fails when it encounters false #14406

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
david-cortes opened this issue Sep 1, 2019 · 1 comment
Closed

Converting char to bool fails when it encounters false #14406

david-cortes opened this issue Sep 1, 2019 · 1 comment

Comments

@david-cortes
Copy link
Contributor

If I initialize a numpy array of C char and try to convert it to numpy booleans, it throws an error whenever it encounters a zero (false).

import numpy as np, ctypes
np.zeros(5, dtype = ctypes.c_char).astype("bool")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-284bcf3dfeb8> in <module>
      1 import numpy as np, ctypes
----> 2 np.zeros(5, dtype = ctypes.c_char).astype("bool")

ValueError: invalid literal for int() with base 10: ''
@seberg
Copy link
Member

seberg commented Sep 3, 2019

Hmmm, this is a bit strange. Probably some very old behaviour. You are right, empty strings should be interpreted as False, the problem will be that changing may be tricky with backwards compatibility

In any case, I will close this for discussion to conginue in gh-9875 which is much more comprehensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants