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: Disabling pandas option display.html.use_mathjax has no effect; add mathjax_ignore to fix #60311

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ I/O
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
- Bug in :meth:`read_stata` where extreme value integers were incorrectly interpreted as missing for format versions 111 and prior (:issue:`58130`)
- Bug in :meth:`read_stata` where the missing code for double was not recognised for format versions 105 and prior (:issue:`58149`)
- Bug in :meth:`set_option` where setting the pandas option ``display.html.use_mathjax`` to ``False`` has no effect (:issue:`59884`)
- Bug in :meth:`to_excel` where :class:`MultiIndex` columns would be merged to a single row when ``merge_cells=False`` is passed (:issue:`60274`)

Period
Expand Down
1 change: 1 addition & 0 deletions pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def _write_table(self, indent: int = 0) -> None:
use_mathjax = get_option("display.html.use_mathjax")
if not use_mathjax:
_classes.append("tex2jax_ignore")
_classes.append("mathjax_ignore")
if self.classes is not None:
if isinstance(self.classes, str):
self.classes = self.classes.split()
Expand Down
6 changes: 4 additions & 2 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,11 @@ def _translate(
if not get_option("styler.html.mathjax"):
table_attr = table_attr or ""
if 'class="' in table_attr:
table_attr = table_attr.replace('class="', 'class="tex2jax_ignore ')
table_attr = table_attr.replace(
'class="', 'class="tex2jax_ignore mathjax_ignore '
)
else:
table_attr += ' class="tex2jax_ignore"'
table_attr += ' class="tex2jax_ignore mathjax_ignore"'
d.update({"table_attributes": table_attr})

if self.tooltips:
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,11 @@ def test_repr_html_ok(self, styler):
def test_repr_html_mathjax(self, styler):
# gh-19824 / 41395
assert "tex2jax_ignore" not in styler._repr_html_()
assert "mathjax_ignore" not in styler._repr_html_()

with option_context("styler.html.mathjax", False):
assert "tex2jax_ignore" in styler._repr_html_()
assert "mathjax_ignore" in styler._repr_html_()

def test_update_ctx(self, styler):
styler._update_ctx(DataFrame({"A": ["color: red", "color: blue"]}))
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,11 @@ def test_repr_html(self, float_frame):
def test_repr_html_mathjax(self):
df = DataFrame([[1, 2], [3, 4]])
assert "tex2jax_ignore" not in df._repr_html_()
assert "mathjax_ignore" not in df._repr_html_()

with option_context("display.html.use_mathjax", False):
assert "tex2jax_ignore" in df._repr_html_()
assert "mathjax_ignore" in df._repr_html_()

def test_repr_html_wide(self):
max_cols = 20
Expand Down