Skip to content

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

Closed

Description

@eric-wieser

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))

Activity

  1. eric-wieser commented on Oct 17, 2017

    @eric-wieser
    MemberAuthor

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions