On Tue, 2022-03-08 at 08:26 -0800, Stefan van der Walt wrote:
> Hi Sebastian,
> 
> On Tue, Mar 8, 2022, at 07:41, Sebastian Berg wrote:
> > just a brief note that:
> > 
> >     https://github.com/numpy/numpy/pull/21145
> > 
> > will add `np.from_dlpack` (to import objects implementing the
> > `__dlpack__` dunder [1].
> 
> In other places in the ecosystem, like pandas and xarray, `from_x`
> and friends live as static methods on their respective classes.  Any
> reason not to add this as `numpy.array.from_dlpack`? We may also want
> to consider adding all the other `from*`'s there and deprecating the
> original usage (without removing it).


One thing I did not mention, is that what the data-api folks included
the symbol in their namespace [1].  So keeping it in the main namespace
has the benefit of aligning with that.


A class-/staticmethod would be an interesting API choice.  But I
suppose it would mainly be nice if we have a clear intention of moving
the others, too?  (Which unfortunately seems slow?)

If we almost certainly only consider duplicating this as methods, I
would tend to not worry about it for this PR – adding it doesn't stop
us from doing that later.
But of course it may still be a good time to discuss it!

An annoyance with methods is that our class is `np.ndarray` with an
awkward `__new__` [2].
So if it is `np.array.from_*` it would not be (only) a static- or
classmethod, but also attached to that function.

Cheers,

Sebastian


[1]
https://data-apis.org/array-api/latest/API_specification/generated/signatures.creation_functions.from_dlpack.html

[2] I suppose there may be a point in moving `np.ndarray(...)` users to
something more appropriate.  And maybe even eventually making
`np.array` the actual class.  But, if possible, the last part would be
a very long haul.


> 

> Stéfan
> 

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to