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

Already on GitHub? Sign in to your account

Slicing corner case: using a length 0 mask as a fancy index raises IndexError. #3469

Closed
mdickinson opened this Issue Jun 25, 2013 · 4 comments

Comments

Projects
None yet
2 participants
Contributor

mdickinson commented Jun 25, 2013

The script below (Python 2.7, NumPy 1.7.1) fails for me with an IndexError:

Traceback (most recent call last):
  File "numpy_masking.py", line 15, in <module>
    do_mask(0)   # Fails with IndexError.
  File "numpy_masking.py", line 10, in do_mask
    data[mask]
IndexError: index 0 is out of bounds for axis 0 with size 0

Is this intended behaviour? I was expecting data[mask] to give an array of shape (0, 3).

import numpy

def do_mask(n):
    data = numpy.random.random((n, 3))
    mask = (
        (data[:, 0] >= 0.2) &
        (data[:, 0] <= 0.8) &
        (data[:, 1] >= 0.2) & 
        (data[:, 1] <= 0.8))

    data[mask]

do_mask(3)   # Succeeds
do_mask(1)   # Succeeds
do_mask(0)   # Fails with IndexError.
Member

seberg commented Jun 26, 2013

This is fixed in master. If it bugs you for 1.7. you could pull that out from my fix (disregard the tests, you will need basic new ones, its impossible to backport those without the rest and tweaking).

Contributor

mdickinson commented Jun 26, 2013

Great! I'll close this report, then. Is there a particular commit I can look at (or a relevant Github issue)?

@mdickinson mdickinson closed this Jun 26, 2013

Member

seberg commented Jun 26, 2013

its one of the commits in gh-2701

Contributor

mdickinson commented Jun 26, 2013

Thanks.

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