removing undocumented use of __array__(dtype, context)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

removing undocumented use of __array__(dtype, context)

mattip
Administrator
A code path and test have been in the code since NumPy 0.4 for a
two-argument variant of ``__array__(dtype=None, context=None)``. It was
activated when calling ``ufunc(op)`` or ``ufunc.reduce(op)`` if
``op.__array__`` existed. However that variant is not documented, and it
is not clear what the intention was for its use.


The code was something like


try:

     op.__array__(dtype, context)

except TypeError:

     op.__array__(dtype)


In PR 15118 https://github.com/numpy/numpy/pull/15118 I proposed to
remove this, so the call is now simply


op.__array__(dtype)


or `op.__array__()` if there is no dtype


Does anyone need the undocumented two-argument variant?


Matti




_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: removing undocumented use of __array__(dtype, context)

Sebastian Berg
On Mon, 2019-12-16 at 21:01 +0200, Matti Picus wrote:

> A code path and test have been in the code since NumPy 0.4 for a
> two-argument variant of ``__array__(dtype=None, context=None)``. It
> was
> activated when calling ``ufunc(op)`` or ``ufunc.reduce(op)`` if
> ``op.__array__`` existed. However that variant is not documented, and
> it
> is not clear what the intention was for its use.
>
>
> The code was something like
>
>
> try:
>
>      op.__array__(dtype, context)
>
> except TypeError:
>
>      op.__array__(dtype)
>
>
> In PR 15118 https://github.com/numpy/numpy/pull/15118 I proposed to
> remove this, so the call is now simply
>
>
> op.__array__(dtype)
>
>
> or `op.__array__()` if there is no dtype
>
>
> Does anyone need the undocumented two-argument variant?
>
I agree, if nobody knows any usecase, I am for trying to remove it. It
seems like a Deprecation will not be super simple here. And since there
are no known use-cases, and any new use-case is better covered by
`__array_ufunc__` (and probably also `__array_wrap__`), removing this
simplifies an already tricky enough corner of NumPy.

Best,

Sebastian


>
> Matti
>
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: removing undocumented use of __array__(dtype, context)

Sebastian Berg
On Mon, 2019-12-16 at 13:41 -0600, Sebastian Berg wrote:

> On Mon, 2019-12-16 at 21:01 +0200, Matti Picus wrote:
> > A code path and test have been in the code since NumPy 0.4 for a
> > two-argument variant of ``__array__(dtype=None, context=None)``. It
> > was
> > activated when calling ``ufunc(op)`` or ``ufunc.reduce(op)`` if
> > ``op.__array__`` existed. However that variant is not documented,
> > and
> > it
> > is not clear what the intention was for its use.
> >
Just to note, our plan is to merge this in a few days, since it seems
like the only way to find out if someone might be using it is to put it
in. We do not expect this at all.

If anyone disagrees or finds a use-case, we can always stop or revert
the change. But such changes will be nicer now that 1.18 is just
branched rather than in a few months.

Best,

Sebastian


> >
> > The code was something like
> >
> >
> > try:
> >
> >      op.__array__(dtype, context)
> >
> > except TypeError:
> >
> >      op.__array__(dtype)
> >
> >
> > In PR 15118 https://github.com/numpy/numpy/pull/15118 I proposed
> > to
> > remove this, so the call is now simply
> >
> >
> > op.__array__(dtype)
> >
> >
> > or `op.__array__()` if there is no dtype
> >
> >
> > Does anyone need the undocumented two-argument variant?
> >
>
> I agree, if nobody knows any usecase, I am for trying to remove it.
> It
> seems like a Deprecation will not be super simple here. And since
> there
> are no known use-cases, and any new use-case is better covered by
> `__array_ufunc__` (and probably also `__array_wrap__`), removing this
> simplifies an already tricky enough corner of NumPy.
>
> Best,
>
> Sebastian
>
>
> > Matti
> >
> >
> >
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > [hidden email]
> > https://mail.python.org/mailman/listinfo/numpy-discussion
>
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

signature.asc (849 bytes) Download Attachment