-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DataFrame with MultiIndex raises TypeError
instead of KeyError
for inexistent keys
#27420
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
Labels
Indexing
Related to indexing on series/frames, not to indexes themselves
MultiIndex
Needs Tests
Unit test(s) needed to prevent regressions
Milestone
Comments
I think you need to be explicit about where the index labels end. In [23]: df.loc[(1, 6), :] which rasies ~/sandbox/pandas/pandas/core/indexes/multi.py in get_loc_level(self, key, level, drop_level)
2814 return (self._engine.get_loc(key), None)
2815 except KeyError as e:
-> 2816 raise KeyError(key) from e
2817 else:
2818 return partial_selection(key)
|
This now raises a KeyError on master |
Yes, that's right. |
jbrockmendel
added a commit
to jbrockmendel/pandas
that referenced
this issue
Oct 18, 2020
8 tasks
JulianWgs
pushed a commit
to JulianWgs/pandas
that referenced
this issue
Oct 26, 2020
…v#15928, pandas-dev#30053 (pandas-dev#37228) * TST: tests for pandas-dev#21168, pandas-dev#27420, pandas-dev#15928, pandas-dev#30053 * use datapath
kesmit13
pushed a commit
to kesmit13/pandas
that referenced
this issue
Nov 2, 2020
…v#15928, pandas-dev#30053 (pandas-dev#37228) * TST: tests for pandas-dev#21168, pandas-dev#27420, pandas-dev#15928, pandas-dev#30053 * use datapath
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Indexing
Related to indexing on series/frames, not to indexes themselves
MultiIndex
Needs Tests
Unit test(s) needed to prevent regressions
Code Sample, a copy-pastable example if possible
Problem description
When a non existent key
.loc
raisesTypeError
. 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
The text was updated successfully, but these errors were encountered: