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

Buggy negative slicing with ix #2600

Closed
wesm opened this issue Dec 27, 2012 · 6 comments
Closed

Buggy negative slicing with ix #2600

wesm opened this issue Dec 27, 2012 · 6 comments
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@wesm
Copy link
Member

wesm commented Dec 27, 2012

http://stackoverflow.com/questions/14035817/slicing-pandas-dataframe-with-negative-index-with-ix-method

    In [1]: df = pd.DataFrame(np.random.randn(10, 4))

    In [2]: df
    Out[2]: 
              0         1         2         3
    0 -3.100926 -0.580586 -1.216032  0.425951
    1 -0.264271 -1.091915 -0.602675  0.099971
    2 -0.846290  1.363663 -0.382874  0.065783
    3 -0.099879 -0.679027 -0.708940  0.138728
    4 -0.302597  0.753350 -0.112674 -1.253316
    5 -0.213237 -0.467802  0.037350  0.369167
    6  0.754915 -0.569134 -0.297824 -0.600527
    7  0.644742  0.038862  0.216869  0.294149
    8  0.101684  0.784329  0.218221  0.965897
    9 -1.482837 -1.325625  1.008795 -0.150439

    In [3]: df.ix[-2:]
    Out[3]: 
              0         1         2         3
    0 -3.100926 -0.580586 -1.216032  0.425951
    1 -0.264271 -1.091915 -0.602675  0.099971
    2 -0.846290  1.363663 -0.382874  0.065783
    3 -0.099879 -0.679027 -0.708940  0.138728
    4 -0.302597  0.753350 -0.112674 -1.253316
    5 -0.213237 -0.467802  0.037350  0.369167
    6  0.754915 -0.569134 -0.297824 -0.600527
    7  0.644742  0.038862  0.216869  0.294149
    8  0.101684  0.784329  0.218221  0.965897
    9 -1.482837 -1.325625  1.008795 -0.150439
@wesm
Copy link
Member Author

wesm commented Dec 28, 2012

It's a binary-search slicing issue on monotonic indexes. Not sure if will fix. deferring to 0.11 after discussion with @changhiskhan

@jreback
Copy link
Contributor

jreback commented Sep 20, 2013

since ix transforms neg indicies to pos this won't work..hmm

but the following do

In [4]: df.iloc[-2:]
Out[4]: 
          0         1         2         3
8 -0.128100  0.033696  0.391006  0.492019
9  0.719473  0.079920  1.710083 -0.291418

In [5]: df[-2:]
Out[5]: 
          0         1         2         3
8 -0.128100  0.033696  0.391006  0.492019
9  0.719473  0.079920  1.710083 -0.291418

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Feb 18, 2014
@jreback jreback modified the milestones: 0.16.0, 0.17.0 Jan 26, 2015
@jonasrauber
Copy link

I just ran into this bug. Are you still planning to fix it?

@jorisvandenbossche
Copy link
Member

I don't think we will fix this.
As it is actually not a bug. ix does label-based indexing when having an integer index, so the result you see is correct. If you want integer positional indexing, you can use df.iloc[-2:]

@jorisvandenbossche jorisvandenbossche modified the milestones: No action, Next Major Release Apr 8, 2016
@jorisvandenbossche
Copy link
Member

@jreback agree to close?

@jreback
Copy link
Contributor

jreback commented Apr 8, 2016

@jorisvandenbossche yep agreed.

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

4 participants