Skip to content

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

Closed
@eric-wieser

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

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