Skip to content

BUG: to_latex, when escaped=True, doesn't escape columns name #61309

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
3 tasks done
lucian-student opened this issue Apr 19, 2025 · 4 comments
Closed
3 tasks done

BUG: to_latex, when escaped=True, doesn't escape columns name #61309

lucian-student opened this issue Apr 19, 2025 · 4 comments
Labels
Bug Duplicate Report Duplicate issue or pull request Styler conditional formatting using DataFrame.style

Comments

@lucian-student
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

df = pd.DataFrame(data=[{"hello":"world"}])
df.columns.name = "hello_world"
df.to_latex("table.tex",escape=True)

Issue Description

Contents of df.columns.name aren't escaped.

Expected Behavior

df.columns.name should be escaped.

Installed Versions

INSTALLED VERSIONS

commit : 0f43794
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.167.4-microsoft-standard-WSL2
Version : #1 SMP Tue Nov 5 00:21:55 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.3
numpy : 1.24.4
pytz : 2025.2
dateutil : 2.9.0.post0
setuptools : 44.0.0
pip : 20.0.2
Cython : 3.0.12
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.6
IPython : 8.12.3
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.5
numba : None
numexpr : 2.8.6
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : 3.8.0
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

@lucian-student lucian-student added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 19, 2025
@chilin0525
Copy link
Contributor

Providing a reproducible result on the main branch for both escape=True and escape=False:

  • escape=True:
    \begin{tabular}{ll}
    \toprule
    hello_world & hello \\
    \midrule
    0 & world \\
    \bottomrule
    \end{tabular}
    
  • escape=False:
    \begin{tabular}{ll}
    \toprule
    hello_world & hello \\
    \midrule
    0 & world \\
    \bottomrule
    \end{tabular}
    

@rhshadrach
Copy link
Member

Thanks for the report! Agreed that column labels should also be escaped. I've also confirmed that index labels are escaped.

cc @attack68

@rhshadrach rhshadrach added Styler conditional formatting using DataFrame.style and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 19, 2025
@chilin0525
Copy link
Contributor

@rhshadrach Is this issue a duplicate of #57362? I noticed that PR #61307 has already been created to address it.

@rhshadrach
Copy link
Member

Indeed, thanks! Closing.

@rhshadrach rhshadrach added the Duplicate Report Duplicate issue or pull request label Apr 19, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Styler conditional formatting using DataFrame.style
Projects
None yet
Development

No branches or pull requests

3 participants