<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Nov 7, 2017 at 12:23 PM Chris Barker <<a href="mailto:chris.barker@noaa.gov">chris.barker@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><br></div></div></div><div dir="ltr"><div class="gmail_extra"><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"><span style="font-size:12.8px"> And then a third abc for indexing support, although, I am not sure how that could get implemented...</span></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>This is the really tricky one -- all ABCs really check is the existence of methods -- making sure they behave the same way is up to the developer of the ducktype.</div><div><br></div><div>which is K, but will require discipline.</div><div><br></div><div>But indexing, specifically fancy indexing, is another matter -- I'm not sure if there even a way with an ABC to check for what types of indexing are support, but we'd still have the problem with whether the semantics are the same!</div><div><br></div><div>For example, I work with netcdf variable objects, which are partly duck-typed as ndarrays, but I think n-dimensional fancy indexing works differently... how in the world do you detect that with an ABC???</div></div></div></div></blockquote><div><br></div><div>We recently worked out a hierarchy of indexing types for xarray. To a crude approximation, we have:</div><div>- "Basic" indexing support for slices and integers. Nearly every array type satisfies this.</div><div>- "Outer" or "orthogonal" indexing with slices, integers and 1D arrays. This is what netCDF4-Python and Fortran/MATLAB support.</div><div>- "Vectorized" indexing with broadcasting and multi-dimensional indexers. NumPy supports a generalization of this, but I would not wish the edge cases involving mixed slices/arrays upon anyone.</div><div>- "Logical" indexing by a boolean array with the same shape.</div><div>- "Exactly like NumPy" for subclasses or wrappers around NumPy arrays.</div><div><br></div><div>There's some ambiguities in this, but that's what specs are for. For most applications, we probably don't need most of these: ABCs for "Basic", "Logical" and "Exactly like NumPy" would go a long ways.</div><div><br></div></div></div>