-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Wrong "Too many indexers" error message when indexing a Series with MultiIndex #14885
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
so So i'll mark this as a bug / error reporting for the 2 cases you have identified. PR's welcome. |
For the record, as a work-around to get the expected |
It doesn't only look the same, it is actually exactly the same for getitem.
Some similar other cases where the multi-indexing gets it wrong (using the same example series):
In this case I would have expected the 'too many indexers' error. Also when slicing the first levels, you get this error message:
which can be very misleading in a real-world use case with a large dataframe and points you in the wrong direction for trying to fix your code (encountered this last week). |
Regarding the other example you give:
I don't think this should ever raise a "IndexingError: Too many indexers" as you actually have a length 2 indexer (so suits the multi-index). But you are correct the interpretation of the tuple here as a list may be a bit inconsistent. |
Code Sample, a copy-pastable example if possible
Problem description
The raised error, and the message, seem wrong to me.
Expected Output
This is what I get if I I take a
DataFrame
with the same index and doBy the way,
s.loc['a', 'b']
(valid key) works just fine, so this is clearly a problem of missing key, and the docs say ".loc
will raise aKeyError
when the items are not found."... and by the way, I would expect the following to raise an
IndexingError: Too many indexers
:... instead the tuple is interpreted as a list of labels rather than as a key, and hence it works "fine". Is this behavior desired? (looks a bit inconsistent to me, but I see that it is generalized, i.e.
DataFrame
s also work this way) If it is, then it is worth fixing the docs where they mention "A list or array of labels, e.g. ['a', 'b', 'c']." to also mention tuples.Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.7.0-1-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: it_IT.utf8
LOCALE: it_IT.UTF-8
pandas: 0.19.0+196.g5f889a2.dirty
nose: 1.3.7
pip: 8.1.2
setuptools: 28.0.0
Cython: 0.23.4
numpy: 1.11.2
scipy: 0.18.1
statsmodels: 0.8.0.dev0+f80669e
xarray: None
IPython: 5.1.0.dev
sphinx: 1.4.8
patsy: 0.3.0-dev
dateutil: 2.5.3
pytz: 2015.7
blosc: None
bottleneck: 1.2.0dev
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.3
openpyxl: None
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: None
bs4: 4.5.1
html5lib: 0.999
httplib2: 0.9.1
apiclient: 1.5.2
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: 0.2.1
The text was updated successfully, but these errors were encountered: