Pandas version checks

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

  • [X] 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
import numpy as np

df = pd.DataFrame(np.random.randn(3, 3), columns=list("ABC"))
df.style.format('$\\beta=$ {:.2%}').set_caption('This is the result with $\\alpha=5$')

Issue Description

When the code above is executed in a Jupyter notebook inside of VS code, the latex is not rendered:

Pandas BUG: Latex fails to render in Jupyter Notebook (in VS Code)

Expected Behavior

The expected behavior is the following:

Pandas BUG: Latex fails to render in Jupyter Notebook (in VS Code)

Notably, this output was produced by using VS Code Export to HTML (which works as expected).

Installed Versions

INSTALLED VERSIONS ------------------ commit : 2e218d10984e9919f0296931d92ea851c6a6faf5 python : 3.10.3.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19044 machine : AMD64 processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United States.1252 pandas : 1.5.3 numpy : 1.22.3 pytz : 2022.1 dateutil : 2.8.2 setuptools : 58.1.0 pip : 23.0.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : 3.0.3 lxml.etree : 4.9.1 html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : 8.5.0 pandas_datareader: None bs4 : 4.11.1 bottleneck : None brotli : None fastparquet : None fsspec : 2022.8.2 gcsfs : None matplotlib : 3.6.1 numba : 0.56.2 numexpr : None odfpy : None openpyxl : 3.0.10 pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : 1.9.1 snappy : None sqlalchemy : None tables : None tabulate : None xarray : 2022.12.0 xlrd : None xlwt : 1.3.0 zstandard : None tzdata : None

Comment From: jrmagers

Also reported here: https://github.com/executablebooks/jupyter-book)](https://github.com/executablebooks/jupyter-book/issues/1826

Comment From: rhshadrach

From the link above, pandas behaves correctly in jupyter-lab. Is there any reason to suspect this is an issue with pandas?

Comment From: jrmagers

From the link above, pandas behaves correctly in jupyter-lab. Is there any reason to suspect this is an issue with pandas?

The only (possible) reason I believe is that it used to work in the past (with an older version of pandas). That's my own observation that I should probably look into.

Comment From: rhshadrach

with an older version of pandas

What version?

Comment From: attack68

Agree with @rhshadrach. If this renders in one system it is not pandas issue.

Have you tried using another math mode identifier. Perhaps VSCode has changed/updated? Is it an option that is configurable in VSCode. Do you need a mathjax addin installed to VSCode?

df = pd.DataFrame(np.random.randn(1, 1), columns=list("A"))
print(df.style.format('\( \\beta= \) {:.2%}').set_caption('This is the result with $\\alpha=5$').to_latex())
\begin{table}
\caption{This is the result with $\alpha=5$}
\begin{tabular}{lr}
 & A \\
0 & \( \beta= \) -156.96% \\
\end{tabular}
\end{table}

This pandas output is correct.

print(df.style.format('$\\beta=$ {:.2%}').set_caption('This is the result with $\\alpha=5$').to_html())
<style type="text/css">
</style>
<table id="T_94ee7">
  <caption>This is the result with $\alpha=5$</caption>
  <thead>
    <tr>
      <th class="blank level0" >&nbsp;</th>
      <th id="T_94ee7_level0_col0" class="col_heading level0 col0" >A</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th id="T_94ee7_level0_row0" class="row_heading level0 row0" >0</th>
      <td id="T_94ee7_row0_col0" class="data row0 col0" >\( \beta= \) -156.96%</td>
    </tr>
  </tbody>
</table>

Are you aware that some browsers / renderers detect pandas dataframes from the HTML CSS class that pandas has attached? Google Colab used to need class="dataframe" but I believe that is now fixed and remove.

You can try:

df.style
    .format('$\\beta=$ {:.2%}')
    .set_caption('This is the result with $\\alpha=5$')
    .set_table_attributes('class="dataframe"')

This has fixed other problems: see here

Comment From: rhshadrach

@jrmagers - friendly ping, it would be helpful to know if @attack68's suggestion above fixes the issue for you.

Comment From: jrmagers

I tried .set_table_attributes('class="dataframe"') and I also tried to_html() and neither worked. To be clear: I think the output looks correct, but VS code is not rendering it. Perhaps this is a VSCode rendering issue?

sidenote: I received a VSCode notification today asking me to take a survey about what I liked and disliked about the Jupyter Notebook experience in VSCode. I took this opportunity to cite this bug report. :)

Comment From: attack68

closing this as pandas unrelated. Feel free to reopen if more info comes to light.