Repository navigation
Update np.bool to be an alias to np.bool_ and un-deprecate it #22021
Description
Activity
Should we do the same for
np.object_vsnp.object?Reacted by Warren Weckesser, Leo Fang and Jacek Laskowski+1 from me,
np.objectis perfectly clear. Less important thanbool, but has the same rationale.In general, will
boolstill be an alias/converted for the underlying numpy boolean type? Is usingboolas thedtypethe most compatible way across<1.20.0,>=1.20.0, <1.25, and going forward?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?
Hi, I come from #23494.
For now, to avoid confussion, perhaps the text of the
FutureWarningshould 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
AttributeErrorraised later.IMO, the confussion comes mainly from the current wording. The warning states that
np.boolwill be deprecated "in the future", but then an attritube exception is raised. Changing the text to reflect thatnp.boolhas already been deprecated, then raising the exception prevents confussion about why the exception has been raised.Reacted by Michael Schmidtnp.boolis back alive and the preferred name for numpy 2.0 (np.bool_is an alias tonp.boolnow):>>> np.bool <class 'numpy.bool'> >>> np.bool_ <class 'numpy.bool'>
Should we do the same for
np.object_vsnp.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
boolhas been addressed.Reacted by Gustavo HylanderWhat is the purpose of
np.bool? Should it be preferred toboolwhen instantiating numpy arrays? Is it faster or more memory efficient?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.
Since NumPy 1.20.0,
np.boolis deprecated (together withnp.intandnp.float). We'd like to keepnp.boolthough, because it's a better name thannp.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:
np.boolagain (butfrom numpy import *is a problem?)np.bool is np.bool_at some point in the (far) future.np.boolhas now been deprecated for four releases, so it's time to take the next step in the next release (1.24.0).