Skip to content

EHN: df.to_latex(escape=True) also escape index names #61307

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

quangngd
Copy link
Contributor

@quangngd quangngd commented Apr 19, 2025

Stage 3. Part of an multi-stages effort: #57880 (comment)
Part 2 has a issue at #59324
But in the process of implementing, I realized the current implementation of df.to_latex(escape) does not go through styler.to_latex but to call styler.format_index. This implementation follows the same flow. So maybe part 2 is not really relevant.

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@@ -824,6 +824,33 @@ def test_to_latex_escape_special_chars(self):
)
assert result == expected

def test_to_latex_escape_special_chars_in_index_names(self):
special_characters = ["&", "%", "$", "#", "_", "{", "}", "~", "^", "\\"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you start the first line of the test with a reference to the issue:

# https://github.com/pandas-dev/pandas/issues/61309

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -824,6 +824,33 @@ def test_to_latex_escape_special_chars(self):
)
assert result == expected

def test_to_latex_escape_special_chars_in_index_names(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing this test pass on main.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, my bad. fixed

@rhshadrach rhshadrach added Styler conditional formatting using DataFrame.style Bug labels Apr 19, 2025
@quangngd
Copy link
Contributor Author

cc @attack68 as the codeowner of styler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: to_latex() does not escape index name
2 participants