<div dir="ltr"><div dir="ltr">On Mon, Sep 16, 2019 at 1:45 PM Peter Andreas Entschev <<a href="mailto:peter@entschev.com">peter@entschev.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">What would be the use case for a duck-array to implement __array__ and<br>
return a NumPy array? Unless I'm missing something, this seems<br>
redundant and one should just use array/asarray functions then. This<br>
would also prevent error-handling, what if the developer intentionally<br>
wants a NumPy-like array (e.g., the original array passed to the<br>
duckarray function) or an exception (instead of coercing to a NumPy<br>
array)?<br></blockquote><div><br></div><div>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.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
On Mon, Sep 16, 2019 at 9:25 PM Chris Barker <<a href="mailto:chris.barker@noaa.gov" target="_blank">chris.barker@noaa.gov</a>> wrote:<br>
><br>
><br>
><br>
> On Mon, Aug 12, 2019 at 4:02 AM Peter Andreas Entschev <<a href="mailto:peter@entschev.com" target="_blank">peter@entschev.com</a>> wrote:<br>
>><br>
>> Apologies for the late reply. I've opened a new PR<br>
>> <a href="https://github.com/numpy/numpy/pull/14257" rel="noreferrer" target="_blank">https://github.com/numpy/numpy/pull/14257</a> with the changes requested<br>
><br>
><br>
> thanks!<br>
><br>
> I've written a small PR on your PR:<br>
><br>
> <a href="https://github.com/pentschev/numpy/pull/1" rel="noreferrer" target="_blank">https://github.com/pentschev/numpy/pull/1</a><br>
><br>
> 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.<br>
><br>
> 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.<br>
><br>
> -CHB<br>
><br>
> --<br>
><br>
> Christopher Barker, Ph.D.<br>
> Oceanographer<br>
><br>
> Emergency Response Division<br>
> NOAA/NOS/OR&R            (206) 526-6959   voice<br>
> 7600 Sand Point Way NE   (206) 526-6329   fax<br>
> Seattle, WA  98115       (206) 526-6317   main reception<br>
><br>
> <a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a><br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div></div>