Skip to content

TST: Fix a doctest in style_render.py #42766

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

Closed
aneesh98 opened this issue Jul 28, 2021 · 3 comments · Fixed by #42778
Closed

TST: Fix a doctest in style_render.py #42766

aneesh98 opened this issue Jul 28, 2021 · 3 comments · Fixed by #42778
Labels
Docs Styler conditional formatting using DataFrame.style

Comments

@aneesh98
Copy link
Contributor

aneesh98 commented Jul 28, 2021

Fix the following doctest in style_render.py file:

pandas/io/formats/style_render.py F

=================================== FAILURES ===================================
________ [doctest] pandas.io.formats.style_render.StylerRenderer.format ________
647 
648         >>> df = pd.DataFrame([[np.nan, 1.0, 'A'], [2.0, np.nan, 3.0]])
649         >>> df.style.format(na_rep='MISS', precision=3) # doctest: +SKIP
650                 0       1       2
651         0    MISS   1.000       A
652         1   2.000    MISS   3.000
653 
654         Using a ``formatter`` specification on consistent column dtypes
655 
656         >>> df.style.format('{:.2f}', na_rep='MISS', subset=[0,1])
Expected:
            0      1          2
    0    MISS   1.00          A
    1    2.00   MISS   3.000000
Got:
    <pandas.io.formats.style.Styler object at 0x7f77b214ea30>

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

(2 durations < 0.005s hidden.  Use -vv to show these durations.)
=========================== short test summary info ============================
FAILED pandas/io/formats/style_render.py::pandas.io.formats.style_render.StylerRenderer.format
============================== 1 failed in 1.70s ===============================

OBSERVATION

The mentioned test returns a Styler object which will render properly in (for instance, a notebook), but will fail the doctest as it will simply return the object.

SOLUTION

Add images of output rendered, in the doctest wherever required. (The approach is mentioned #42674 (comment), for the documentation of background_gradient()) or add a # doctest: +SKIP if necessary.

@aneesh98 aneesh98 added Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels Jul 28, 2021
@aneesh98
Copy link
Contributor Author

take

@attack68
Copy link
Contributor

Styler is a different object to the rest of pandas, its methods affect the visual output of browsers and other renderers.

These docstrings were created as a balance between helping the user and being able to read the code as a developer.

Adding images has the disadvantage of being more difficult for developers to edit, but being visually accurate.
The doc test as is has the advantages of being editable by devs and visible to users, but the disadvantage of failing a doc test.

The soultion here, as is with many styler doc tests is to skip it.

@aneesh98
Copy link
Contributor Author

Thank you so much for the feedback @attack68

@rhshadrach rhshadrach added Docs Styler conditional formatting using DataFrame.style and removed Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels Jul 29, 2021
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants