Skip to content

Incorrect Message in KeyError with MultiIndex #27250

Closed
@djbarker

Description

@djbarker

Code Sample

X = pd.DataFrame(dict(A=[1, 1, 1, 2, 2, 2], B=[1, 2, 3, 1, 2, 3], C=[1, 2, 3, 4, 5, 6], D=list("abcdef")))
X = X.set_index(["A", "B", "C"])
X.loc[(1, 1, 2), :] 

Problem description

This correctly throws a KeyError but the message is incorrect, instead of showing "KeyError: (1, 1, 2)" it shows "KeyError: 42"

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Linux
OS-release: 4.18.16-200.fc28.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: 0.19.1
pyarrow: 0.13.0
xarray: None
IPython: 7.1.1
sphinx: None
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.3.0
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions