8000 WIP: Actually try deprecating non-tuple nd-indices by seberg · Pull Request #4434 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

WIP: Actually try deprecating non-tuple nd-indices #4434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

seberg
Copy link
Member
@seberg seberg commented Mar 4, 2014

Just here for discussion. I am not sure it isn't too brutal. Also there is a test failure right now, which I think is probably another bug...

@@ -228,6 +228,10 @@

if (make_tuple) {
/* We want to interpret it as a tuple, so make it one */
if (DEPRECATE("interpreting a sequence (not baseclass tuple) as a "
"multidimensional indexing is deprecated.") < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about: "using a non-tuple sequence for multidimensional indexing is deprecated; use arr[tuple(foo)] instead of arr[foo]"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will also add a test. Not sure about the failure, I think gradient possibly doesn't work with multidimensional datetime input, but I find it a bit puzzling that advanced indexing worked and normal doesn't. It might have something to do with arr[[0]] returning an array while arr[0,] returns a scalar...

@njsmith
Copy link
Member
njsmith commented Mar 4, 2014

I like it, and no-one objected on the list. Not sure what's up with the test failure, but otherwise LGTM...

@njsmith
Copy link
Member
njsmith commented Mar 4, 2014

Though, it would be good to also have:

  • a test
  • a mention in the release notes
  • a deprecation bug to remind us later

@argriffing
Copy link
Contributor

This PR would change the behavior of this code?

>>> a = np.arange(10).reshape(5, 2)
>>> a
array([[0, 1],
       [2, 3],
       [4, 5],
       [6, 7],
       [8, 9]])
>>> a[(2, 1)]
5
>>> a[np.array([2, 1])]                                                         
array([[4, 5],
       [2, 3]])

@njsmith
Copy link
Member
njsmith commented Mar 4, 2014

No, both of those are unaffected. All it does changes is to start issuing a
DeprecationWarning for a[[2, 1]], which right now acts like a[(2, 1)]
instead of a[np.array([2, 1])]. We want it to eventually act like
np.array([2, 1]).

On Tue, Mar 4, 2014 at 7:17 PM, argriffing notifications@github.com wrote:

This PR would change the behavior of this code?

a = np.arange(10).reshape(5, 2)
a
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
a[(2, 1)]
5
a[np.array([2, 1])]
array([[4, 5],
[2, 3]])


Reply to this email directly or view it on GitHubhttps://github.com//pull/4434#issuecomment-36662374
.

Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org

@seberg
Copy link
Member Author
seberg commented Mar 5, 2014

Updated (made it a futurewarning, too). But the datetime gradient issue is open, so...

@seberg
Copy link
Member Author
seberg commented Aug 31, 2014

This should work now (though it is not unlikely that there is a tuple call misisng somewhere). Doesn't necessarily make it an easier decision :)

@seberg
Copy link
Member Author
seberg commented Sep 15, 2014

Note, this also changes the behaviour of tuple subclasses (or warns about a change). Tuple subclasses apparently were always handled like tuples before. I don't care much either way but the new test will need fixing (tests would fail if rerun currently), and before we put this in, we need to decide on it.
Should probably run some tests suits as a next step to see how much of scipy, etc. are broken by this ;).

@homu
Copy link
Contributor
homu commented Jun 21, 2015

☔ The latest upstream changes (presumably #5990) made this pull request unmergeable. Please resolve the merge conflicts.

@seberg
Copy link
Member Author
seberg commented Jul 8, 2015

I have updated this (resolved merge conflict. Obviously it is not ready, since the 1.9. release notes are probably not the right place ;), but could discuss this again.

@homu
Copy link
Contributor
homu commented Jul 25, 2015

☔ The latest upstream changes (presumably #6047) made this pull request unmergeable. Please resolve the merge conflicts.

Such indexing has problem with ambiguouity for example whether
`arr[[[0], [1]]]` is `arr[[0], [1]]` or `arr[asarray([[0], [1]])]`

Adds the tuple cast where it is necessary (at the time of writing
this, it is not unlikely that there are some hidden ones missing).
@seberg
Copy link
Member Author
seberg commented Dec 2, 2015

Updated this a bit, but getting some weirder errors, weeding out everything, especially in the masked array stuff seems a bit tricky. Anyone who wants to pick it up, be my guest, it is getting a bit annoying :).

@@ -39,6 +39,13 @@ DeprecationWarning to error
FutureWarning to changed behavior
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Multidimensional indexing with anything but a base class tuple is
deprecated. This means that code such as ``arr[[slice(None)]]`` has to
be changed to ``arr[tuple([slice(None)])]``. This is necessary to avoid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write: arr[(slice(None),)] or simply arr[slice(None),]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, yeah, though that would somewhat defeat the purpose ;). should make the example longer... Anyway, doesn't look like 1.11 change.
Hmmm, reading my last comment, part of me wonders why the masked arrays are always so tricky when doing indexing changed.

EDIT: should make the list explicit.

@homu
Copy link
Contributor
homu commented Jan 28, 2016

☔ The latest upstream changes (presumably #7134) made this pull request unmergeable. Please resolve the merge conflicts.

AmitAronovitch added a commit to AmitAronovitch/numpy that referenced this pull request May 21, 2016
Recommended type for nd-indexing is a tuple. See numpy#4434
charris pushed a commit to charris/numpy that referenced this pull request May 22, 2016
Recommended type for nd-indexing is a tuple. See numpy#4434
}
else if (make_tuple == 1) {
if (DEPRECATE_FUTUREWARNING(
"multi dimensional indexing tuple was not base class. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good reason to deprecate this? Allowing subclasses of tuple doesn't seem unreasonable, as there's still no ambiguity

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, probably not, I probably wasn't sure and just thought I will go with the extreme version and make it less extreme from there ;).

@eric-wieser
Copy link
Member

@seberg: Can you make this editable so that I can pick it up?

# just set y equal to the the array `f`.
if f.dtype.char in ["M", "m"]:
y = f.view('int64')
y = f.view(otype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is some weird problems in gradient that made it work only if it did the wrong, fancy, indexing. I guess this maybe somehow fixed/worked around it, it is possible that the commit message explains more, but likely not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would not rule out that other datetime fixes in the meantime may have made this better, or that changing things at another place would be more correct.

@seberg
Copy link
Member Author
seberg commented Apr 7, 2017

Anyway, the problem with this is less the work to make it work, but more making the decision to do this very noisy deprecation which affects quite a lot of things.

@eric-wieser
Copy link
Member
eric-wieser commented Apr 7, 2017

One thing we could do right now is merge all the fixes that make numpy only ever index with tuples internally. That way subclassers don't need to deal with this "feature" if all they care about is numpy itself

@seberg
Copy link
Member Author
seberg commented Apr 7, 2017

Yeah, I guess so, though unless you add a compile time option to give the warning or so (and use it during testing), there will be no guarantee for it in the future and its useless. There is a bit of a downer, that manual tuple conversion is slower (probably because python has kwarg parsing overhead or so), but there is no point being annoyed by it I suppose.

@eric-wieser
Copy link
Member
eric-wieser commented Sep 14, 2017

@seberg, I went ahead and rebased this at #9686 (although I accidentally pushed over this PR first...)

@eric-wieser eric-wieser force-pushed the force-tuple branch 2 times, most recently from 175e0f1 to 81aa766 Compare September 14, 2017 04:43
@charris
Copy link
Member
charris commented Sep 25, 2017

Should we close #4434?

@seberg
Copy link
Member Author
seberg commented Sep 25, 2017

Sure, why not, could always reopen anyway if there were a reason for it.

@seberg seberg closed this Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
0