Skip to content
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

ERR: validate boolean indexing with iloc #8976

Closed
jreback opened this issue Dec 3, 2014 · 5 comments
Closed

ERR: validate boolean indexing with iloc #8976

jreback opened this issue Dec 3, 2014 · 5 comments
Labels
Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@jreback
Copy link
Contributor

jreback commented Dec 3, 2014

xref #8956

This should raise a ValueError.

In [18]: s = Series(np.arange(5,1,-1))

In [19]: s
Out[19]: 
0    5
1    4
2    3
3    2
dtype: int64

In [20]: s.iloc[[True,False,True]]
Out[20]: 
0    5
2    3
dtype: int64
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Error Reporting Incorrect or improved errors from pandas labels Dec 3, 2014
@jreback jreback added this to the 0.16.0 milestone Dec 3, 2014
@jorisvandenbossche
Copy link
Member

As I said in the other issue, numpy has the same behaviour as pandas (which is strange), although there docs say the same as we think it should be: "Boolean arrays must be of the same shape as the initial dimensions of the array being indexed" (http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays):

In [2]: np.__version__
Out[2]: '1.8.1'

In [3]: a = np.arange(5)

In [4]: a
Out[4]: array([0, 1, 2, 3, 4])

In [5]: a[np.array([True, False, True])]
Out[5]: array([0, 2])

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jorisvandenbossche
Copy link
Member

In the meantime, numpy has changed this behaviour (already deprecated in 1.10, errors in 1.13), so we should follow I think. This should raise:

In [1]: np.__version__
Out[1]: '1.13.3'

In [2]: pd.__version__
Out[2]: '0.22.0.dev0+202.g492040b'

In [3]: a = np.arange(5)

In [4]: a[np.array([True, False, True])]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-4-7375c598447e> in <module>()
----> 1 a[np.array([True, False, True])]

IndexError: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 3

In [5]: s = pd.Series(a)

In [6]: s.iloc[np.array([True, False, True])]
Out[6]: 
0    0
2    2
dtype: int64

@jorisvandenbossche jorisvandenbossche modified the milestones: Next Major Release, 0.22.0 Nov 24, 2017
@jreback
Copy link
Contributor Author

jreback commented Nov 24, 2017

yep agreed. I think they wrapped around the booleans before.

@jreback jreback modified the milestones: 0.23.0, Next Major Release Apr 14, 2018
@jbrockmendel
Copy link
Member

We now raise IndexError: Item wrong length 3 instead of 4. on this which looks about right

@jbrockmendel
Copy link
Member

Closed by #26911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

3 participants