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

.ix() failure for mixed-integer index #1799

Closed
lodagro opened this issue Aug 22, 2012 · 3 comments
Closed

.ix() failure for mixed-integer index #1799

lodagro opened this issue Aug 22, 2012 · 3 comments
Assignees
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@lodagro
Copy link
Contributor

lodagro commented Aug 22, 2012

from mailinglist
cc @ruidc

With the following DataFrame:

df = pandas.DataFrame(index=[1, 10, 'C', 'E'], columns=[1, 2, 3])

df.ix[df.index[:-1]] works
df.ix[:-1] doesn't

df.ix[[1, 10]] does not work
df.ix[pandas.Index([1, 10], dtype=df.index.dtype)] works
df.ix[10] does not work
@lodagro
Copy link
Contributor Author

lodagro commented Sep 5, 2012

Just spend a bit of time on fixing this.

In [9]: df
Out[9]: 
           1         2         3
1   0.476835 -0.541463  0.142869
10  2.027024  0.434206 -1.092403
C   1.108003  1.692173 -1.413435
E   0.688612 -1.082818  1.289867

In [10]: df.ix[10]
Out[10]: 
1    2.027024
2    0.434206
3   -1.092403
Name: 10

In [11]: df.ix[[1, 10]]
Out[11]: 
           1         2         3
1   0.476835 -0.541463  0.142869
10  2.027024  0.434206 -1.092403

When starting to fix the slices and df.ix[list], i noticed that slicing from label to position (or reversed) and selecting a range with both labels and positions on 0.8.1 has (at least for me) unexpected behavior (even for indexes without integers). So what can we expect from pandas to behave in these situations?

In [24]: df
Out[24]: 
          A         B         C         D         E
a  0.613189  0.689797 -0.234561  2.147688 -2.809169
b  0.203202  0.025470  0.862836  1.250575  1.166273
c  0.002628  0.413194 -1.367218  1.112502  0.059427
d -2.734778 -1.671669  0.029811 -1.469516 -0.043275
e  1.560336  0.845640  1.517610 -0.861052 -0.206302

In [25]: df.ix[[2, 'e']]
Out[25]: 
          A        B        C         D         E
2       NaN      NaN      NaN       NaN       NaN
e  1.560336  0.84564  1.51761 -0.861052 -0.206302

In [26]: df.ix[2:'e']
Out[26]: 
          A         B         C         D         E
a  0.613189  0.689797 -0.234561  2.147688 -2.809169
b  0.203202  0.025470  0.862836  1.250575  1.166273
c  0.002628  0.413194 -1.367218  1.112502  0.059427
d -2.734778 -1.671669  0.029811 -1.469516 -0.043275
e  1.560336  0.845640  1.517610 -0.861052 -0.206302

In [27]: df.ix[['b', 4]]
Out[27]: 
          A        B         C         D         E
b  0.203202  0.02547  0.862836  1.250575  1.166273
4       NaN      NaN       NaN       NaN       NaN

In [28]: df.ix['b':4]
Out[28]: 
Empty DataFrame
Columns: array([A, B, C, D, E], dtype=object)
Index: array([], dtype=object)

@ghost ghost assigned wesm Sep 11, 2012
@wesm
Copy link
Member

wesm commented Sep 11, 2012

df.ix['b':4] was not intended to be a supported API. It only works by accident because:

  1. the index is sorted
  2. in python 2 integers are comparable with strings

I'll have to poke around at some point about raising a helpful error...

I'll look into fixing the cited bugs now

@wesm
Copy link
Member

wesm commented Sep 11, 2012

fixed in c32cc6e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

2 participants