Skip to content

TST: Fix for doctest in style_render.py -> pandas.io.formats.style_re… #42778

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

Merged
merged 4 commits into from
Aug 1, 2021
Merged

TST: Fix for doctest in style_render.py -> pandas.io.formats.style_re… #42778

merged 4 commits into from
Aug 1, 2021

Conversation

aneesh98
Copy link
Contributor

This pull request fixes the doctest pandas.io.formats.style_render.StylerRenderer.format

Following this commit, all the doctests in style_render.py file passed.

Output:

python -m pytest --doctest-modules pandas/io/formats/style_render.py
========================================================= test session starts =========================================================
platform linux -- Python 3.8.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/aneesh/Desktop/Side Projects/ops/pandas, configfile: pyproject.toml
plugins: forked-1.3.0, asyncio-0.15.1, anyio-3.3.0, cov-2.12.1, instafail-0.4.2, hypothesis-6.14.3, xdist-2.3.0
collected 3 items                                                                                                                     

pandas/io/formats/style_render.py ...

--------------------------- generated xml file: /home/aneesh/Desktop/Side Projects/ops/pandas/test-data.xml ---------------------------
======================================================== slowest 30 durations =========================================================
1.06s call     pandas/io/formats/style_render.py::pandas.io.formats.style_render.StylerRenderer.format

(8 durations < 0.005s hidden.  Use -vv to show these durations.)
========================================================== 3 passed in 1.15s ==========================================================

@pep8speaks
Copy link

pep8speaks commented Jul 28, 2021

Hello @aneesh98! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-08-01 12:10:04 UTC

@attack68
Copy link
Contributor

is it better to have two spaces before # as per PEP?

@@ -698,7 +700,7 @@ def format(
Using a ``formatter`` with LaTeX ``escape``.

>>> df = pd.DataFrame([["123"], ["~ ^"], ["$%#"]])
>>> s = df.style.format("\\textbf{{{}}}", escape="latex").to_latex()
>>> s = df.style.format("\\textbf{{{}}}", escape="latex").to_latex() # doctest: +SKIP
Copy link
Contributor

Choose a reason for hiding this comment

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

to_latex() actually produces a string result.. maybe this could be doctested.

Copy link
Contributor Author

@aneesh98 aneesh98 Jul 29, 2021

Choose a reason for hiding this comment

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

The command line output I got by running this test is not pretty printed actually as it is in the docs, thus failing the doctest:

________ [doctest] pandas.io.formats.style_render.StylerRenderer.format ________
694         ...
695         <td .. ><a href="a.com/&lt;div&gt;&lt;/div&gt;">&lt;div&gt;&lt;/div&gt;</a></td>
696         <td .. ><a href="a.com/&#34;A&amp;B&#34;">&#34;A&amp;B&#34;</a></td>
697         <td .. >NA</td>
698         ...
699 
700         Using a ``formatter`` with LaTeX ``escape``.
701 
702         >>> df = pd.DataFrame([["123"], ["~ ^"], ["$%#"]])
703         >>> df.style.format("\\textbf{{{}}}", escape="latex").to_latex()
Expected:
    \begin{tabular}{ll}
    {} & {0} \\
    0 & \textbf{123} \\
    1 & \textbf{\textasciitilde \space \textasciicircum } \\
    2 & \textbf{\$\%\#} \\
    \end{tabular}
Got:
    '\\begin{tabular}{ll}\n{} & {0} \\\\\n0 & \\textbf{123} \\\\\n1 & \\textbf{\\textasciitilde \\space \\textasciicircum } \\\\\n2 & \\textbf{\\$\\%\\#} \\\\\n\\end{tabular}\n'

Please let me know if I am missing something here.
Thanks.

@aneesh98
Copy link
Contributor Author

aneesh98 commented Jul 29, 2021

is it better to have two spaces before # as per PEP?

Sorry actually I have added two spaces before # , referring to other doctests in other files (for instance frame.py).

@aneesh98 aneesh98 requested a review from attack68 July 30, 2021 03:23
Copy link
Contributor

@attack68 attack68 left a comment

Choose a reason for hiding this comment

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

lgtm, all of these can be skipped

@aneesh98
Copy link
Contributor Author

lgtm, all of these can be skipped

Thanks

@KrishnaSai2020
Copy link
Contributor

@aneesh98 I would recommend merging master into your branch. #42790 and #42820 fixes the CI checks so they should now be all green once you merge

@aneesh98
Copy link
Contributor Author

aneesh98 commented Aug 1, 2021

@aneesh98 I would recommend merging master into your branch. #42790 and #42820 fixes the CI checks so they should now be all green once you merge

Hi @KrishnaSai2020. Thank you for this.

@attack68 attack68 merged commit 01076c6 into pandas-dev:master Aug 1, 2021
@attack68
Copy link
Contributor

attack68 commented Aug 1, 2021

thanks @aneesh98

sthagen added a commit to sthagen/pandas-dev-pandas that referenced this pull request Aug 2, 2021
TST: Fix for doctest in style_render.py (pandas-dev#42778)
feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
* TST: Fix for doctest in style_render.py -> pandas.io.formats.style_render.StylerRenderer.format

* Fixed PEP8 Issues

* Fixed Whitespace & Longline PEP8 issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: Fix a doctest in style_render.py
4 participants