-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Missing labels when applying style gives a KeyError #32125
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
Thanks @simonvh I tried this on master and didn't get any error;
|
Ah, that's something that I should have checked. Thanks for doing so! |
Sorry, wrote that in a bit of a rush - mind if I keep this open till we verify when it was fixed and if there's a test? Will check this tomorrow |
@simonvh are you sure
is what you ran to get the error? I just tried it on a clean environment with just pandas v1.0.1 installed and it passed |
Yes, only this code. This is with pandas installed from conda-forge:
|
Thanks - TBH I don't know what's going on then, I just tried installing from conda-forge and got no error:
|
Ah. I see. It's only when running the snippet in a Jupyter notebook. Then you get this error:
|
Got it, thanks @simonvh ! Back to the issue, regarding your two suggestions:
A more precise error message would be helpful, I imagine the core devs would accept a PR for this - would you interested in submitting a PR?
The doc says:
so I think it's reasonable to expect users to pass a valid slice. The decision to not support slicing with missing labels seems very deliberate |
A recent PR has imporved the error message. The missing label 'c' is now communicated:
|
Code Sample, a copy-pastable example if possible
Problem description
This issue occurs when passing a list of columns to
bar()
where one (or more) of the columns is not present in the dataframe. It will give aKeyError
:Expected Output
This error does not describe the problem. I would expect one of two possible outcomes:
bar()
that are not present._apply()
inio/formats/style.py
to deal with missing labels.I would prefer option 2, but I can image that woudl not be the preferred behavior of pandas :-).
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-17134-Microsoft
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0.post20200209
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: