Skip to content

Change in bool type coersion? #16023

Closed

Description

@LevN0

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.

Activity

  1. eric-wieser commented on Apr 20, 2020

    @eric-wieser
    Member

    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.

  2. seberg commented on Apr 20, 2020

    @seberg
    Member

    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.

  3. added this to the 1.18.4 release milestone on Apr 20, 2020
  4. added
    Priority: highHigh priority, also add milestones for urgent issues
    on Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions