[Numpy-discussion] np.{bool,float,int} deprecation
Robert Kern
robert.kern at gmail.com
Wed Dec 9 16:27:14 EST 2020
On Wed, Dec 9, 2020 at 4:08 PM Aaron Meurer <asmeurer at gmail.com> wrote:
> On Wed, Dec 9, 2020 at 9:41 AM Sebastian Berg
> <sebastian at sipsolutions.net> wrote:
> >
> > On Mon, 2020-12-07 at 14:18 -0700, Aaron Meurer wrote:
> > > Regarding np.bool specifically, if you want to deprecate this, you
> > > might want to discuss this with us at the array API standard
> > > https://github.com/data-apis/array-api (which is currently in RFC
> > > stage). The spec uses bool as the name for the boolean dtype.
> > >
> > > Would it make sense for NumPy to change np.bool to just be the
> > > boolean
> > > dtype object? Unlike int and float, there is no ambiguity with bool,
> > > and NumPy clearly doesn't have any issues with shadowing builtin
> > > names
> > > in its namespace.
> >
> > We could keep the Python alias around (which for `dtype=` is the same
> > as `np.bool_`).
> >
> > I am not sure I like the idea of immediately shadowing the builtin.
> > That is a switch we can avoid flipping (without warning); `np.bool_`
> > and `bool` are fairly different beasts? [1]
>
> NumPy already shadows a lot of builtins, in many cases, in ways that
> are incompatible with existing ones. It's not something I would have
> done personally, but it's been this way for a long time.
>
Sometimes, we had the function first before Python added them to the
builtins (e.g. sum(), any(), all(), IIRC). I think max() and min() are the
main ones that we added after Python did, and we explicitly exclude them
from __all__ to avoid clobbering the builtins.
Shadowing the types (bool, int, float) historically tended to be more
problematic than those functions. The first releases of numpy _did_ have
those as the scalar types. That empirically turned out to cause more
problems for people than sum() or any(), so we renamed the scalar types to
have the trailing underscore. We only left the shadowed names as aliases
for the builtins because enough people still had `dtype=np.float` in their
code that we didn't want to break.
All that said, "from numpy import *" is less common these days. We have
been pretty successful at getting people on board with the np campaign.
--
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20201209/04fd243f/attachment.html>
More information about the NumPy-Discussion
mailing list