Skip to content
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

Wrong "Too many indexers" when value in series with MultiIndex is None #24474

Closed
ludaavics opened this issue Dec 28, 2018 · 3 comments
Closed
Labels
Error Reporting Incorrect or improved errors from pandas good first issue MultiIndex

Comments

@ludaavics
Copy link

Code Sample, a copy-pastable example if possible

import pandas as pd
s = pd.Series([None, 'ad', 'bc', 'bd'], index=pd.MultiIndex.from_product([['a', 'b'], ['c', 'd']]))
s.loc['a', 'c']  # raises IndexingError: Too many indexers
s.loc(axis=0)['a', 'c']  # workaround

Problem description

Similar to #14885 but, in our case, the key is indeed present in the Multi Index (but the associated value is None).
Credit for the workaround goes to @bluenote10

Expected Output

Nothing (i.e. None object)

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Darwin
OS-release: 17.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: 4.0.0
pip: 18.1
setuptools: 39.1.0
Cython: None
numpy: 1.14.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: 1.8.1
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.4
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: 1.0.4
lxml: None
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.7
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@gfyoung gfyoung added Error Reporting Incorrect or improved errors from pandas MultiIndex good first issue labels Dec 30, 2018
@gfyoung
Copy link
Member

gfyoung commented Dec 30, 2018

I might consider adding this example to the existing issue, given how similar they are.

What do you think?

cc @jreback

@jreback
Copy link
Contributor

jreback commented Dec 30, 2018

When accessing a MI tuple you almost always need to specify all axes as a matter of course, see the documentation: http://pandas-docs.github.io/pandas-docs-travis/advanced.html#using-slicers

In [8]: s.loc[('a', 'c'), :]
Out[8]: 
a  c    None
   d      ad
dtype: object

If documentation is unclear, certainly would take PR to update.

@jreback jreback closed this as completed Dec 30, 2018
@ludaavics
Copy link
Author

ludaavics commented Dec 30, 2018

@jreback I understand your comment on dataframes, but not on series: there isn't really any ambiguity about which column we want? But point well taken.
Also -- wouldn't we expect s.loc[('a', 'c'), :] (or whatever other appropriate syntax) to return just None?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas good first issue MultiIndex
Projects
None yet
Development

No branches or pull requests

3 participants