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

sort_index throws IndexError for some permutations #26053

Closed
soerenwolfers opened this issue Apr 11, 2019 · 3 comments

Comments

@soerenwolfers
Copy link

commented Apr 11, 2019

Code Sample

df = pd.DataFrame(list(range(8)))
a.index = pd.MultiIndex.from_product([[0,1]]*3)
a.sort_index(level=[1,2,0])

Problem description

This throws an IndexEror: pop index out of range.
If I change the order to [2,0,1], it doesn't.

python: 3.6.6.final.0
pandas: 0.24.2
numpy: 1.15.4

@soerenwolfers soerenwolfers changed the title sort_index sometimes throws IndexError for some permutations sort_index throws IndexError for some permutations Apr 11, 2019

@WillAyd

This comment has been minimized.

Copy link
Member

commented Apr 11, 2019

Please provide fully reproducible code - it's not clear what a here is

@WillAyd WillAyd added the Needs Info label Apr 11, 2019

@jayanthkaturi

This comment has been minimized.

Copy link
Contributor

commented Apr 11, 2019

## a -> df
import pandas as pd
df = pd.DataFrame(list(range(8)))
df.index = pd.MultiIndex.from_product([[0,1]]*3)
df.sort_index(level=[1,2,0])
@WillAyd

This comment has been minimized.

Copy link
Member

commented Apr 11, 2019

OK thanks for clarifying. The both seem to fail:

df.sort_index(level=[2,1,0])
df.sort_index(level=[1,2,0])

sort_remaining doesn't appear to have an impact. One pattern that may be apparent there is that both failures use all of the level and have the initial level as the last of the sort.

May or may not be related to issue - in any case investigation and PRs are always welcome!

@WillAyd WillAyd added Bug MultiIndex and removed Needs Info labels Apr 11, 2019

@WillAyd WillAyd added this to the Contributions Welcome milestone Apr 11, 2019

jayanthkaturi added a commit to jayanthkaturi/pandas that referenced this issue Apr 11, 2019

BUG: sort_index throws IndexError for some permutations (pandas-dev#2…
…6053)

    - (lev - i) will be negative if 0th index is at the end of level list

jayanthkaturi added a commit to jayanthkaturi/pandas that referenced this issue Apr 14, 2019

BUG: sort_index throws IndexError for some permutations (pandas-dev#2…
…6053)

    - (lev - i) will be out of bounds for pop if the first index dim is to be sorted last

jayanthkaturi added a commit to jayanthkaturi/pandas that referenced this issue Apr 16, 2019

BUG: sort_index throws IndexError for some permutations (pandas-dev#2…
…6053)

    - (lev - i) will be out of bounds for pop if the first index dim is to be sorted last

jayanthkaturi added a commit to jayanthkaturi/pandas that referenced this issue Apr 16, 2019

BUG: sort_index throws IndexError for some permutations (pandas-dev#2…
…6053)

    - (lev - i) will be out of bounds for pop if the first index dim is to be sorted last

@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Apr 16, 2019

jayanthkaturi added a commit to jayanthkaturi/pandas that referenced this issue Apr 21, 2019

BUG: sort_index throws IndexError for some permutations (pandas-dev#2…
…6053)

    - (lev - i) will be out of bounds for pop if the first index dim is to be sorted last

jayanthkaturi added a commit to jayanthkaturi/pandas that referenced this issue Apr 21, 2019

BUG: sort_index throws IndexError for some permutations (pandas-dev#2…
…6053)

    - (lev - i) will be out of bounds for pop if the first index dim is to be sorted last

jayanthkaturi added a commit to jayanthkaturi/pandas that referenced this issue Apr 23, 2019

BUG: sort_index throws IndexError for some permutations (pandas-dev#2…
…6053)

    - (lev - i) will be out of bounds for pop if the first index dim is to be sorted last

jayanthkaturi added a commit to jayanthkaturi/pandas that referenced this issue Apr 24, 2019

BUG: sort_index throws IndexError for some permutations (pandas-dev#2…
…6053)

    - (lev - i) will be out of bounds for pop if the first index dim is to be sorted last

jreback added a commit that referenced this issue Apr 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.