Skip to content

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

Closed
seberg wants to merge 1 commit into
numpy:masterfrom
seberg:force-tuple
Closed

seberg wants to merge 1 commit into
numpy:masterfrom
seberg:force-tuple

Conversation

@seberg

@seberg seberg commented Mar 4, 2014

Copy link
Copy Markdown
Member

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...

Comment thread numpy/core/src/multiarray/mapping.c Outdated

Copy link
Copy Markdown
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
Copy Markdown
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

njsmith commented Mar 4, 2014

Copy link
Copy Markdown
Member

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

@njsmith

njsmith commented Mar 4, 2014

Copy link
Copy Markdown
Member

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
Copy Markdown
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

njsmith commented Mar 4, 2014

Copy link
Copy Markdown
Member

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 [email protected] 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

seberg commented Mar 5, 2014

Copy link
Copy Markdown
Member Author

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

@seberg

seberg commented Aug 31, 2014

Copy link
Copy Markdown
Member Author

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

seberg commented Sep 15, 2014

Copy link
Copy Markdown
Member Author

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

homu commented Jun 21, 2015

Copy link
Copy Markdown
Contributor

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

@seberg

seberg commented Jul 8, 2015

Copy link
Copy Markdown
Member Author

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

homu commented Jul 25, 2015

Copy link
Copy Markdown
Contributor

☔ 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

seberg commented Dec 2, 2015

Copy link
Copy Markdown
Member Author

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 :).

Copy link
Copy Markdown
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
Copy Markdown
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

homu commented Jan 28, 2016

Copy link
Copy Markdown
Contributor

☔ 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

seberg commented Apr 7, 2017

Copy link
Copy Markdown
Member Author

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

eric-wieser commented Apr 7, 2017 •

Copy link
Copy Markdown
Member

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

seberg commented Apr 7, 2017

Copy link
Copy Markdown
Member Author

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

eric-wieser commented Sep 14, 2017 •

Copy link
Copy Markdown
Member

@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

charris commented Sep 25, 2017

Copy link
Copy Markdown
Member

Should we close #4434?

@seberg

seberg commented Sep 25, 2017

Copy link
Copy Markdown
Member Author

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