[Numpy-discussion] On responding to dubious ideas (was: Re: Advanced indexing: "fancy" vs. orthogonal)
robert.kern at gmail.com
Wed Apr 8 16:20:33 EDT 2015
On Wed, Apr 8, 2015 at 8:40 PM, Ralf Gommers <ralf.gommers at gmail.com> wrote:
> To address in detail the list of Matthew you mention above:
> * implement orthogonal indexing as a method arr.sensible_index[...]
> That's basically Jaime's PR.
> * implement the current non-boolean fancy indexing behavior as a method
> Not that harmful, but only makes sense in combination with the next steps.
Well, since we got the peanut butter in our meta, I might as well join in
I think this step is useful even without the deprecation steps. First,
allow me to rename things in a less judgy fashion:
* arr.ortho_ix is a property that allows for orthogonal indexing, a la
* arr.fancy_ix is a property that implements the current numpy-standard
Even though arr.fancy_ix "only" replicating the default semantics, having
it opens up some possibilities.
Other array-like objects can implement both of these with the same names.
Thus, to write generic code that exploits the particular behaviors of one
of these semantics, you just make sure to use the property that behaves the
way you want. Then you don't care what the default syntax does on that
object. You don't have to test if an object has arr.__orthogonal_indexing__
and have two different code paths; you just use the property that behaves
the way you want.
It also allows us to issue warnings when the default indexing syntax is
used for some of the behaviors that are weird corner cases, like [1, :,
array]. This is one of those corner cases where the behavior is probably
not what anyone actually *wants*; it was just the only thing we could do
that is consistent with the desired semantics of the rest of the cases. I
think it would be reasonable to issue a warning if the default indexing
syntax was used with it. It's probably a sign that the user thought that
indexing worked like orthogonal indexing. The warning would *not* be issued
if the arr.fancy_ix property was used, since that is an explicit signal
that the user is specifically requesting a particular set of behaviors. I
probably won't want to ever *deprecate* the behavior for the default
syntax, but a warning is easy to deal with even with old code that you
don't want to modify directly.
Lastly, I would appreciate having some signal to tell readers "pay
attention; this is nontrivial index manipulation; here is a googleable term
so you can look up what this means". I almost always use the default fancy
indexing, but I'd use the arr.fancy_ix property for the nontrivial cases
just for this alone.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion