-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: iloc fails with non lex-sorted MultiIndex #13797
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
Comments
@YG-Riku actually the fix should start here
|
@jreback That's the point where I stumbled on too. Just commenting out the lines: # ax0 = self.obj._get_axis(0)
# if isinstance(ax0, MultiIndex):
# result = self._handle_lowerdim_multi_index_axis0(tup)
# if result is not None:
# return result diminishes the error (and the warning too). But I am not sure about the consequence of this removal of the codes (any side-effect?). |
almost certainly needs to be more selective lots and lots of indexing tests must still pass |
I think I can do some trials-and-errors with the existing test cases of pandas/tests. But if there is a need to prepare a decent set of new test codes, that will be too much burden for me. (Anyway, I will start looking into the test cases ... ) |
no as I said there are hundreds of tests already |
Thank you for the comment. I will try. It is exciting to have a chance to contribute!. (But, please don't wait for me. Probably the time I can spare for this would be mostly on weekends.) |
I found that the following simple amendment works as jreback suggested. @@ -903,7 +903,7 @@ class _NDFrameIndexer(object):
# 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':
result = self._handle_lowerdim_multi_index_axis0(tup)
if result is not None:
return result What is the next step? |
you submit a PR with tests and the fix see here: http://pandas.pydata.org/pandas-docs/stable/contributing.html |
* commit 'v0.19.0rc1-25-ga7469cf': (471 commits) ENH: Add divmod to series and index. (pandas-dev#14208) Fix generator tests to run (pandas-dev#14245) BUG: GH13629 Binned groupby median function with empty bins (pandas-dev#14225) TST/TEMP: fix pyqt to 4.x for plotting tests (pandas-dev#14240) DOC: added example to Series.map showing use of na_action parameter (GH14231) DOC: split docstring into multiple lines in excel.py (pandas-dev#14073) MAINT: Use __module__ in _DeprecatedModule. (pandas-dev#14181) ENH: Allow true_values and false_values options in read_excel (pandas-dev#14002) DOC: fix incorrect example in unstack docstring (GH14206) (pandas-dev#14211) BUG: iloc fails with non lex-sorted MultiIndex pandas-dev#13797 BUG: add check for infinity in __call__ of EngFormatter In gbq.to_gbq allow the DataFrame column order to differ from schema BLD: require cython if tempita is needed DOC: add source links to api docs (pandas-dev#14200) BUG: compat with Stata ver 111 Fix: F999 dictionary key '2000q4' repeated with different values (pandas-dev#14198) BLD: Test for Python 3.5 with C locale BUG: DatetimeTZBlock can't assign values near dst boundary BUG: union_categorical with Series and cat idx BUG: fix str.contains for series containing only nan values ...
Code Sample, a copy-pastable example if possible
df1 (whose index is not lex sorted) fails with iloc access:
Expected Output
df2 (whose index is lex sorted) works as expected:
This attributeError does not occur when the DataFrame.values consist of numpy objects (e.g. numpy.int32) because they have the ndim attribute. (Although the performance warning remains, it may be another issue).
I found that the addition of an if statement can remedy this in pandas/core/indexing.py. This just makes the _getitem_tuple(self, tup) be aware of objects without the ndim attribute, as _getitem_nested_tuple(self, tup) is (I will prepare a pull request if it is helpful.)
output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: