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

COMPAT: warn on ambiguous .ix indexing #7187

Closed
bjonen opened this issue May 20, 2014 · 5 comments
Closed

COMPAT: warn on ambiguous .ix indexing #7187

bjonen opened this issue May 20, 2014 · 5 comments
Labels
Compat pandas objects compatability with Numpy or Python functions Deprecate Functionality to remove in pandas Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@bjonen
Copy link
Contributor

bjonen commented May 20, 2014

In []: df = pd.DataFrame(index=range(10),columns=['a','b',1])

In []: df
Out[]:
     a    b    1
0  NaN  NaN  NaN
1  NaN  NaN  NaN
2  NaN  NaN  NaN
3  NaN  NaN  NaN
4  NaN  NaN  NaN
5  NaN  NaN  NaN
6  NaN  NaN  NaN
7  NaN  NaN  NaN
8  NaN  NaN  NaN
9  NaN  NaN  NaN

In []: df.ix[:,[0]]
Out[]:
     1
0  NaN
1  NaN
2  NaN
3  NaN
4  NaN
5  NaN
6  NaN
7  NaN
8  NaN
9  NaN

In []: df.ix[:,[0,1,2]]
Out[]:
     1    1    1
0  NaN  NaN  NaN
1  NaN  NaN  NaN
2  NaN  NaN  NaN
3  NaN  NaN  NaN
4  NaN  NaN  NaN
5  NaN  NaN  NaN
6  NaN  NaN  NaN
7  NaN  NaN  NaN
8  NaN  NaN  NaN
9  NaN  NaN  NaN

I know in this case one should use iloc, It's not clear what ix should do in this case, but the df.ix[:,[0]] case is certainly not what is expected.

How about either

  • issuing a warning or
  • raising an Exception

when asked to ix an index like this.

@jreback
Copy link
Contributor

jreback commented May 20, 2014

this IS expected from ix though; it tries to 'guess' as you have a numeric index. use iloc instead.

http://pandas-docs.github.io/pandas-docs-travis/indexing.html#indexing-fallback

@bjonen
Copy link
Contributor Author

bjonen commented May 20, 2014

But if the guess is numeric index, then shouldn't it throw an IndexError as 0 is not in the index?

@jreback
Copy link
Contributor

jreback commented May 20, 2014

nope....that is the defined behavior of .ix it assumes you mean the 0th index (as prior to loc/iloc no way to say get me the 0th column). That is why you are encouraged to use loc/iloc and not ix (however it was kept for back-compat reasons).

I agree its not intuitive and should not guess, but noone put in effort to put up the warning.

ok...so will mark this as a issue for 0.15.0 then (to put up a warning in a case like this)

@jreback jreback added this to the 0.15.0 milestone May 20, 2014
@jreback jreback changed the title Strange behavior on mixed index when indexing with ix COMPAT: warn on ambiguous .ix indexing May 20, 2014
@bjonen
Copy link
Contributor Author

bjonen commented May 20, 2014

Ok thanks

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

Closing due to deprecation in #15113

@jorisvandenbossche jorisvandenbossche modified the milestones: No action, Next Major Release Jan 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Deprecate Functionality to remove in pandas Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

4 participants