Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rgommers opened this issue Jul 21, 2022 · 8 comments
Closed

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

rgommers opened this issue Jul 21, 2022 · 8 comments

Comments

@rgommers
Copy link
Member

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

@eric-wieser
Copy link
Member

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

@rgommers
Copy link
Member Author

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

@zachcoleman
Copy link

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?

@zombinator0
Copy link

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?

@ghylander
Copy link

ghylander commented Apr 18, 2023

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.

@rgommers
Copy link
Member Author

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.

@ogencoglu
Copy link

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

@seberg
Copy link
Member

seberg commented Oct 7, 2024

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
Projects
None yet
Development

No branches or pull requests

8 participants