Boolean indexing edge case #2704

Closed
wesm opened this Issue Nov 2, 2012 · 7 comments

Comments

Projects
None yet
4 participants

wesm commented Nov 2, 2012

This looks like a bug to me:

arr = np.array([[]]).T
k = np.array([], dtype=bool)
arr[k]
arr[k] = 0

(NumPy 1.6.1, have not checked git master yet)

Owner

njsmith commented Nov 2, 2012

I agree.

(The above code gives errors for both getitem and setitem. But
indexing an empty array with an empty index should just return another
empty array.)

It's particularly bizarre how this behaviour goes away (and becomes
correct) if you take out the ".T" in the code. I guess something
involving F- versus C-contiguity...?

@seberg, this seems closely related to the things you've been working
on lately, any thoughts? Do your PRs already fix this by chance?

On 2 Nov 2012 22:54, "Wes McKinney" notifications@github.com wrote:

This looks like a bug to me:

arr = np.array([[]]).T
k = np.array([], dtype=bool)
arr[k]
arr[k] = 0


Reply to this email directly or view it on GitHub.

Member

seberg commented Nov 2, 2012

Yes, this is what seberg/numpy@f685ed6 fixes. Just for the curious, the untransposed array is shaped (1,0) the transposed (0,1). That is what causes the difference, taking nothing from something work, but taking nothing from nothing fails.

Owner

njsmith commented Nov 2, 2012

Ah-hah, cool. Something to make sure ends up on the list of tests then, I
guess.

On Fri, Nov 2, 2012 at 11:14 PM, seberg notifications@github.com wrote:

Yes, this is what seberg/numpy@f685ed6seberg/numpy@f685ed6. Just for the curious, the untransposed array is shaped (1,0) the
transposed (0,1). That is what causes the difference, taking nothing from
something work, but taking nothing from nothing fails.


Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/2704#issuecomment-10033230.

mrshu commented Dec 30, 2012

Hey,

I'd like to write the test you proposed but the code above gives me this exception:

IndexError: index 0 is out of bounds for axis 0 with size 0

Is there anything I'm doing wrong? What do you think should the test look like?

Member

seberg commented Dec 30, 2012

@mrshu did you merge my PR gh-2701? Actually it already should be testing this corner case as a set of automatic tests trying out many different possibilities. But I guess an explicit test can't hurt, especially to help tracking down what exactly got bad when it does.

mrshu commented Dec 30, 2012

@seberg ouch, no, I didn't. Seeing that, it doesn't make much sense to write another test for it.

I think this issue can be closed along wih #2701

Member

seberg commented May 11, 2013

This is fixed with gh-2701.

seberg closed this May 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment