<p dir="ltr">On Nov 30, 2015 12:19 PM, "Sebastian Berg" <<a href="mailto:sebastian@sipsolutions.net">sebastian@sipsolutions.net</a>> wrote:<br>
><br>
> On Mo, 2015-11-30 at 18:42 +0100, Lluís Vilanova wrote:<br>
> > Hi,<br>
> ><br>
> > TL;DR: There's a pending pull request deprecating some behaviour I find<br>
> >        unexpected. Does anyone object?<br>
> ><br>
> > Some time ago I noticed that numpy yields unexpected results in some very<br>
> > specific cases. An array can be used to index multiple elements of a single<br>
> > dimension:<br>
> ><br>
> >     >>> a = np.arange(8).reshape((2,2,2))<br>
> >     >>> a[ np.array([[0], [0]]) ]<br>
> >     array([[[[0, 1],<br>
> >              [2, 3]]],<br>
> >            [[[0, 1],<br>
> >              [2, 3]]]])<br>
> ><br>
> > Nonetheless, if a list is used instead, it is (unexpectedly) transformed into a<br>
> > tuple, resulting in indexing across multiple dimensions:<br>
> ><br>
> >     >>> a[ [[0], [0]] ]<br>
> >     array([[0, 1]])<br>
> ><br>
> > I.e., it is interpeted as:<br>
> ><br>
> >     >>> a[ [0], [0] ]<br>
> >     array([[0, 1]])<br>
> ><br>
> > Or what is the same:<br>
> ><br>
> >     >>> a[( [0], [0] )]<br>
> >     array([[0, 1]])<br>
> ><br>
> ><br>
> > I've been informed that there's a pending pull request that deprecates this<br>
> > behaviour [1], which could in the future be reverted to what is expected (at<br>
> > least what I expect) from the documents (except for an obscure note in [2]).<br>
> ><br>
><br>
><br>
> Obviously, I am not against this ;). I have to admit it worries me a<br>
> bit, because there is quite a bit of code doing things like:<br>
><br>
> >>> slice_object = [slice(None)] * 5<br>
> >>> slice_object[2] = 3<br>
> >>> arr[slice_object]<br>
><br>
> and all of this code (numpy also has a lot of it), will probably have to<br>
> change the last line to be:<br>
><br>
> >>> arr[tuple(slice_object)]</p>
<p dir="ltr">This seems like an improvement to me, so I'm +1 on deprecating. I agree that it might be a very long time before we can actually change the behavior though.</p>
<p dir="ltr">I think it would make sense to split it into two separate, parallel deprecations: one for lists like in Lluís's example that are coerceable to an integer array, and one for lists like in your example that contain slices and stuff. The first case needs a FutureWarning, is incredibly confusing, and is unlikely to be used on purpose; the second only needs a DeprecationWarning, is less confusing, and is probably in broader use, so might want a longer deprecation period.</p>
<p dir="ltr">-n</p>