Skip to content

BUG: iloc fails with non lex-sorted MultiIndex #13797 #14038

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

Closed
wants to merge 3 commits into from
Closed

BUG: iloc fails with non lex-sorted MultiIndex #13797 #14038

wants to merge 3 commits into from

Conversation

ygriku
Copy link
Contributor

@ygriku ygriku commented Aug 19, 2016

corrected how iloc handles tuple-keys for multiindex

@codecov-io
Copy link

codecov-io commented Aug 19, 2016

Current coverage is 85.23% (diff: 100%)

Merging #14038 into master will decrease coverage by <.01%

@@             master     #14038   diff @@
==========================================
  Files           140        140          
  Lines         50563      50563          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits          43101      43099     -2   
- Misses         7462       7464     +2   
  Partials          0          0          

Powered by Codecov. Last update 6c73e76...1cf86a1

@shoyer
Copy link
Member

shoyer commented Aug 19, 2016

Yikes! This is a testament to how convoluted the indexing code currently is. If we did this right, it would not be possible for code using iloc to get anywhere near checks for multi-indexes.

@jorisvandenbossche
Copy link
Member

If we did this right, it would not be possible for code using iloc to get anywhere near checks for multi-indexes.

But should it? For iloc it shouldn't matter if you have a multi-index or not how the indexer is interpreted

dat = np.arange(1, 26).reshape(5, 5)
df = pd.concat([strCol, pd.DataFrame(dat)], axis=1)
df1 = pd.DataFrame(df.values, index=ind_nonLex)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

construct the expected result and use tm.assert_frame_equal

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Aug 19, 2016
@@ -903,7 +903,7 @@ def _getitem_lowerdim(self, tup):

# we maybe be using a tuple to represent multiple dimensions here
ax0 = self.obj._get_axis(0)
if isinstance(ax0, MultiIndex):
if isinstance(ax0, MultiIndex) and self.name != 'iloc':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment here (or can update the previous one), with the issue number and a 1-line about what is happening here

@jreback
Copy link
Contributor

jreback commented Aug 19, 2016

Yikes! This is a testament to how convoluted the indexing code currently is. If we did this right, it would not be possible for code using iloc to get anywhere near checks for multi-indexes.

This is not a helpful comment. This is just an implemention detail of the indexer. It could be a sub-class but its not, otherwise this would just be an overriden method.

@shoyer
Copy link
Member

shoyer commented Aug 19, 2016

This is not a helpful comment. This is just an implemention detail of the indexer. It could be a sub-class but its not, otherwise this would just be an overriden method.

This fix looks fragile to me. That said, it's probably the right choice for now. It fixes the problem at hand, but its not obvious that it's fully correct, because too many different code paths reuse the same logic in different ways.

@jreback
Copy link
Contributor

jreback commented Sep 9, 2016

can you rebase / update?

@ygriku
Copy link
Contributor Author

ygriku commented Sep 10, 2016

Yes. I can probably find a time tomorrow.

corrected how iloc handles tuple-keys for multiindex
added comments and modified test code
apply pep8radius to tests/test_multilevel.py
@ygriku
Copy link
Contributor Author

ygriku commented Sep 13, 2016

@jreback
Sorry for taking this long time. I added some comments, and modified the test code so that the test purpose became clear (i.e. iloc handles tuple as an integer locator instead of trying to interpret as multiindex representation.)

@jreback jreback added this to the 0.19.0 milestone Sep 13, 2016
@jreback jreback closed this in fb25cca Sep 13, 2016
@jreback
Copy link
Contributor

jreback commented Sep 13, 2016

thanks!

@ygriku ygriku deleted the mi-iloc-fix branch August 24, 2018 09:18
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 MultiIndex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: iloc fails with non lex-sorted MultiIndex
5 participants