-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: to_latex does not escape % with percent formatter #61478
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
Boiled it down to the implementation of |
Thanks for the report. I believe the intention is that if the user is introducing their own symbols, they can decide to escape them if they desire. cc @attack68 |
This is not a bug. It is as documented. "Escaping is done before formatter". See the documentation example: Using a formatter with HTML escape and Na rep for a case which requires escaping first. |
Yes, it is indeed documented for For
It does not explicitly tell what happens if it is set to True and only mentions its impact on the column names. print(pd.DataFrame({"x": ["%"]}).to_latex(escape=False)) \begin{tabular}{ll}
\toprule
& x \\
\midrule
0 & % \\
\bottomrule
\end{tabular} vs. print(pd.DataFrame({"x": ["%"]}).to_latex(escape=True)) \begin{tabular}{ll}
\toprule
& x \\
\midrule
0 & \% \\
\bottomrule
\end{tabular} So, for |
DataFrame to_latex was re-engineered for version 2.0.0 to use the Styler mechanics (this was to reduce maintenance burden and avoid dual implementations of same feature where one was much more out of date). Really it shouldnt exist at all and all its arguments were monkey patched to suit Styler. |
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
Issue Description
When using
"{:.0%}"
to format floating point values as percentages, the percent signs are not correctly escaped even if explicitly specified. This applies toDataFrame.to_latex
andStyler.to_latex
.Output:
Expected Behavior
Installed Versions
pandas : 2.2.3
numpy : 2.0.2
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : 3.0.11
sphinx : None
IPython : 8.30.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : 1.4.2
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.10.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.4
lxml.etree : None
matplotlib : 3.10.0
numba : 0.60.0
numexpr : 2.10.2
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : 2.9.10
pymysql : None
pyarrow : 18.1.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : 2.0.36
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : 0.23.0
tzdata : 2024.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: