<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Nov 4, 2017 at 6:47 AM, Marten van Kerkwijk <span dir="ltr"><<a href="mailto:m.h.vankerkwijk@gmail.com" target="_blank">m.h.vankerkwijk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
You just summarized excellently why I'm on a quest to change `asarray`<br>
to `asanyarray` within numpy</blockquote><div><br></div><div>+1 -- we should all be using asanyarray() most of the time. However a couple notes:</div><div><br></div><div>asarray() pre-dates asanyarray() by a LOT. asanyarray was added to better handle subclasses, but there is a lot of legacy code out there.</div><div><br></div><div>An legacy coders -- I know that I still usually use asarray without thinking about it -- sorry!</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Obviously, this covers only ndarray<br>
subclasses, not duck types, though I guess in principle one could use<br>
the ABC registration mechanism mentioned above to let those types pass<br>
through.<br></blockquote><div><br></div><div>The trick there is that what does it mean to be duck-typed to an ndarray? For may applications its' critical that the C API be the same, so duck-typing doesn't really apply.</div><div><br></div><div>And in other cases, in only needs to support a small portion of the numpy API. IS essence, there are an almost infinite number of possible ABCs for an ndarray...</div><div><br></div><div>For my part, I've been known to write custom "array_like" code -- it checks for the handful of methods I know I need to use, and tI test it against the small handful of duck-typed arrays that I know I want my code to work with.</div><div><br></div><div>Klunky, and maybe we could come up with a standard way to do it and include that in numpy, but I'm not sure that ABCs are the way to do it.</div><div><br></div><div><br></div><div>-CHB</div><div><br></div></div><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><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></div>
</div></div>