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

BUG: DataFrame.style.bar.to_latex does not output valid LaTeX #54082

Closed
2 of 3 tasks
olofahlen opened this issue Jul 11, 2023 · 1 comment
Closed
2 of 3 tasks

BUG: DataFrame.style.bar.to_latex does not output valid LaTeX #54082

olofahlen opened this issue Jul 11, 2023 · 1 comment
Labels
Closing Candidate May be closeable, needs more eyeballs IO LaTeX to_latex Styler conditional formatting using DataFrame.style

Comments

@olofahlen
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
print(pd.DataFrame([[123]]).style.bar().to_latex())

Issue Description

The output of the code above is

\begin{tabular}{lr}
 & 0 \\
0 & \width10em \backgroundlinear-gradient(90deg, #d65f5f 100.0%, transparent 100.0%) 123 \\
\end{tabular}

Expected Behavior

This does not look like valid LaTeX at all.

  1. There is probably no command called width10em.
  2. LaTeX commands cannot contain -. Here it looks like \backgroundlinear-gradient is supposed to correspond to something but ends up calling a LaTeX command called \backgroundlinear.
  3. Arguments to commands are not passed with parentheses, so (90deg, #d65f5f 100.0%, transparent 100.0%) looks incorrect.
  4. LaTeX comments are created by using %, so the line above becomes 0 & \width10em \backgroundlinear-gradient(90deg, #d65f5f 100.0.
  5. The output does not compile even when including all packages referenced on https://pandas.pydata.org/docs/reference/api/pandas.io.formats.style.Styler.to_latex.html. The compiler fails with Undefined control sequence.

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.9.15.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1160.62.1.el7.x86_64
Version : #1 SMP Tue Apr 5 13:02:25 PDT 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.24.1
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 66.1.1
pip : 23.0
Cython : None
pytest : 7.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : 1.0.3
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.9.0
pandas_datareader: None
bs4 : 4.11.2
bottleneck : None
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.3
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.0
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.0
snappy : None
sqlalchemy : 2.0.16
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : 0.19.0
tzdata : None

@olofahlen olofahlen added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 11, 2023
@attack68
Copy link
Contributor

Since this issue has been raised one could say that this is a documentation issue. However, on the other hand bar is an HTML method. It uses CSS and is not designed to produce charts in LaTeX.

Within the to_latex it is documented that one should not use HTML CSS commands, if one does the use the argument convert_css=True and unavailable HTML CSS will be dropped

@attack68 attack68 added Styler conditional formatting using DataFrame.style IO LaTeX to_latex Closing Candidate May be closeable, needs more eyeballs and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs IO LaTeX to_latex Styler conditional formatting using DataFrame.style
Projects
None yet
Development

No branches or pull requests

2 participants