-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
Current coverage is 85.23% (diff: 100%)@@ 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
|
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. |
But should it? For |
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) | ||
|
There was a problem hiding this comment.
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
@@ -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': |
There was a problem hiding this comment.
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
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. |
can you rebase / update? |
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
@jreback |
thanks! |
git diff upstream/master | flake8 --diff
corrected how iloc handles tuple-keys for multiindex