On Mon, Sep 16, 2019 at 1:45 PM Peter Andreas Entschev email@example.com wrote:
What would be the use case for a duck-array to implement __array__ and return a NumPy array? Unless I'm missing something, this seems redundant and one should just use array/asarray functions then. This would also prevent error-handling, what if the developer intentionally wants a NumPy-like array (e.g., the original array passed to the duckarray function) or an exception (instead of coercing to a NumPy array)?
Dask arrays are a good example. They will want to implement __duck_array__ (or whatever we call it) because they support duck typed versions of NumPy operation. They also (already) implement __array__, so they can converted into NumPy arrays as a fallback. This is convenient for moderately sized dask arrays, e.g., so you can pass one into a matplotlib function.
On Mon, Sep 16, 2019 at 9:25 PM Chris Barker firstname.lastname@example.org wrote:
On Mon, Aug 12, 2019 at 4:02 AM Peter Andreas Entschev <
Apologies for the late reply. I've opened a new PR https://github.com/numpy/numpy/pull/14257 with the changes requested
I've written a small PR on your PR:
Essentially, other than typos and copy editing, I'm suggesting that a
duck-array could choose to implement __array__ if it so chooses -- it should, of course, return an actual numpy array.
I think this could be useful, as much code does require an actual numpy
array, and only that class itself knows how best to convert to one.
Christopher Barker, Ph.D. Oceanographer
Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion
NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion