-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: "IndexingError: Too many indexers" when accessing a None value using .loc through a MultiIndex #34318
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
@dechamps thanks for the report! Using an example that is not of length-1 (that doesn't seem to matter):
So it is indeed only when the Series value that gets accessed is actually |
The problem lies here: pandas/pandas/core/indexing.py Lines 819 to 821 in a9ad632
If the result is Contributions to fix this are always welcome! |
Can i work on this? |
@pedrooa Sure, that would be very welcome! |
I've managed to get it to work by changing the deafult return of _handle_lowerdim_multi_index_axis0(tup) to False instead of None, and then i check it as such:
Is this a valid solution? |
The problem, I think, is that So I think we need another way: either by raising an error and catching that in the layer above, or either with a custom object like |
Ah yes, you are correct. I think that the cleanest solution would be raising an exception. If it catches something it simply doesn't return anything. As such:
It seems to solve this problem. |
Steps to reproduce
Expected output
Actual output
Additional information
If any value other than
None
(evennp.nan
) is used, the code behaves correctly.If a single index level is used, the code behaves correctly.
Workaround
Seems to work if
.loc(axis=0)[('Level1', 'Level2')]
is used instead.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.8.3.candidate.1
python-bits : 64
OS : Linux
OS-release : 5.6.0-1-amd64
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.0.3
numpy : 1.18.2
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3
Cython : None
pytest : 4.6.9
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 4.6.9
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: