Skip to content

Update np.bool to be an alias to np.bool_ and un-deprecate it #22021

Description

@rgommers

Since NumPy 1.20.0, np.bool is deprecated (together with np.int and np.float). We'd like to keep np.bool though, because it's a better name than np.bool_ and is unambiguous.

There was a long email thread on this topic: https://mail.python.org/archives/list/[email protected]/thread/NZWX22G5L7I5LOMKQ7HIRECUZXV6NA34/#NZWX22G5L7I5LOMKQ7HIRECUZXV6NA34. The approach @seberg suggested there was:

  1. Go ahead for now (deprecate)
  2. Add a FutureWarning at some point that we will start to export np.bool again (but from numpy import * is a problem?)
  3. Aim to make np.bool is np.bool_ at some point in the (far) future.

np.bool has now been deprecated for four releases, so it's time to take the next step in the next release (1.24.0).

Activity

  1. added this to the 1.24.0 release milestone on Jul 21, 2022
  2. eric-wieser commented on Jul 21, 2022

    @eric-wieser
    Member

    Should we do the same for np.object_ vs np.object?

  3. rgommers commented on Jul 21, 2022

    @rgommers
    MemberAuthor

    +1 from me, np.object is perfectly clear. Less important than bool, but has the same rationale.

  4. zachcoleman commented on Dec 19, 2022

    @zachcoleman

    In general, will bool still be an alias/converted for the underlying numpy boolean type? Is using bool as the dtype the most compatible way across <1.20.0, >=1.20.0, <1.25, and going forward?

  5. zombinator0 commented on Jan 26, 2023

    @zombinator0

    Hi, if this issue is untaken, I would like to have this as my first issue. Can I please get some pointers on where to start?

  6. ghylander commented on Apr 18, 2023

    @ghylander

    Hi, I come from #23494.

    For now, to avoid confussion, perhaps the text of the FutureWarning should be changed?
    From the curent text to something along the lines of "Starting in v1.24, 'np.bool' was deprecated in favour of 'np.bool_', but will be aliased to 'np.bool_' in the future. For now, please use 'np.bool_'"?

    Provides more information about what is going on, and seems less confusing/conflicting when paired with the AttributeError raised later.

    IMO, the confussion comes mainly from the current wording. The warning states that np.bool will be deprecated "in the future", but then an attritube exception is raised. Changing the text to reflect that np.bool has already been deprecated, then raising the exception prevents confussion about why the exception has been raised.

  7. rgommers commented on Jan 31, 2024

    @rgommers
    MemberAuthor

    np.bool is back alive and the preferred name for numpy 2.0 (np.bool_ is an alias to np.bool now):

    >>> np.bool
    <class 'numpy.bool'>
    >>> np.bool_
    <class 'numpy.bool'>

    Should we do the same for np.object_ vs np.object?

    This wasn't done. Can still be done at any time but isn't a blocker for 2.0, so I'll open a new issue for it now to not forget about it. Closing this one to mark that the issue with bool has been addressed.

  8. ogencoglu commented on Oct 6, 2024

    @ogencoglu

    What is the purpose of np.bool ? Should it be preferred to bool when instantiating numpy arrays? Is it faster or more memory efficient?

  9. seberg commented on Oct 7, 2024

    @seberg
    Member

    It's a different scalar that behaves slightly differently (there are two reasons for this, historically because numpy scalars pretend to be arrays in part, and in part because Python bools behave more like ints sometimes.)

    EDIT: and no, as dtype= it doesn't matter, Python bool is just converted to NumPy bool. There is no dtype that behaves exactly like the Python bool.

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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions