Skip to content

DataFrame with MultiIndex raises TypeError instead of KeyError for inexistent keys  #27420

Closed
@epassaro

Description

@epassaro

Code Sample, a copy-pastable example if possible

import pandas as pd

a = {'A': [1, 2, 3, 4], 'B': [5, 6, 7, 8], 'C': [9, 10, 11, 12]}

df = pd.DataFrame.from_records(a, index=['A', 'B'])

df.loc[(1,6)]

Problem description

When a non existent key .loc raises TypeError. Is this the intended behavior?

Expected Output

Maybe should raise KeyError

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 4.18.0-25-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: 4.5.0
pip: 19.0.3
setuptools: 41.0.0
Cython: 0.29.12
numpy: 1.16.4
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.6.1
sphinx: 1.5.6
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: 3.5.2
numexpr: 2.6.9
feather: None
matplotlib: 3.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.5
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesMultiIndexNeeds TestsUnit test(s) needed to prevent regressions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions