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

Skip to content

Change in bool type coersion? #16023

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
LevN0 opened this issue Apr 20, 2020 · 2 comments · Fixed by #16068
Closed

Change in bool type coersion? #16023

LevN0 opened this issue Apr 20, 2020 · 2 comments · Fixed by #16068
Labels
00 - Bug 06 - Regression Priority: high High priority, also add milestones for urgent issues

Comments

@LevN0
Copy link

LevN0 commented Apr 20, 2020

In all past versions of NumPy dating back at least a decade, using astype(bool) on a str of '0' obtained False and on any other integer as True. Now the result is always True.

Reproducing code example:

import numpy as np

np.asarray(['0', '1']).astype('bool')

Before 1.18.3:
array([False, True], dtype=bool)

After 1.18.3:
array([True, True], dtype=bool)

Numpy/Python version information:

1.18.3 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)]

Other Thoughts

Seems to have been introduced by #15929. The prior behavior was logical, and saved execution time doing multiple type conversions.

@eric-wieser
Copy link
Member

eric-wieser commented Apr 20, 2020

Related to #9875. I'd argue that the behavior isn't logical at all, but the fact remains that we didn't intend to change this behavior in a patch release.

#15766 is the offending change in master corresponding to the backport linked at the top.

@seberg
Copy link
Member

seberg commented Apr 20, 2020

Dang, yes, booleans are so hopelessly inconsistent here, and I did not think of them, too bad we did not have tests for this :(. Aside from the point release change, which is very unfortunate...

I somewhat think we should probably just put a FutureWarning on it and change it as fast as reasonably possible. Being out of sync with ourselves and especially Python doesn't help anyone, because it seems like there may be good logic here, when the logic is just inconsistent.

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Apr 20, 2020
@charris charris added this to the 1.18.4 release milestone Apr 20, 2020
@seberg seberg added the Priority: high High priority, also add milestones for urgent issues label Apr 21, 2020
seberg added a commit to seberg/numpy that referenced this issue Apr 27, 2020
While the legacy behaviour of casting strings to booleans by
first converting the string to an integer is undersireable in
general. It will require a Deprecation/FutureWarning to do the
transition.
Changing this accidentally was thus a regression.

Closes numpygh-16023
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label May 2, 2020
@charris charris modified the milestones: 1.18.4 release, 1.19.0 release May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 06 - Regression Priority: high High priority, also add milestones for urgent issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants