Skip to content

Change __repr__ of np.bool_ #12950

@sauln

Description

@sauln

np.bool_ causes lots of confusion because it does not compare with builtin bool intuitively.

As mentioned in #5942, #7913 (maybe more as well), changing the __repr__ from
[True, False]
to
[np.bool_(True), np.bool_(False)]
would prevent much of the confusion.

Reproducing code example:

>>> import numpy as np
>>> t, f = np.bool_(True), np.bool_(False)
>>> t, f
(True, False)
>>> True, False
(True, False)
>>> t is True, f is False
(False, False)

They are identical. This can be very confusing if you don't know the type of t and f ahead of time.

Numpy/Python version information:

This was tested with Python 3.7 and Numpy version '1.16.1'.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions