TST: Fix doctests in style.py
See original GitHub issuetl;dr
Fix the numerous doctests that are giving errors in the style.py file:
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.apply
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.applymap
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.background_gradient
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.hide_columns
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.hide_index
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.highlight_between
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.highlight_quantile
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.pipe
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.set_properties
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.set_table_attributes
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.set_table_styles
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.set_td_classes
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.set_tooltips
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.text_gradient
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.to_latex
FAILED pandas/io/formats/style.py::pandas.io.formats.style.Styler.where
======================================================================== 16 failed, 1 passed, 1 warning in 0.76s ========================================================================
Detailed instructions
Each of the doctests failed for different reasons. You can see the reason for each of them by running the command below:
python -m pytest --doctest-modules pandas/io/formats/style.py
In general, the above errors can be fixed with things like:
- Fixing a typo (a missing comma, a misspelled variable name…)
- Adding an object that hasn’t been defined (like, if
df
is used, but no sample datasetdf
has been first defined) - Fixing the expected output, when it’s wrong
- In exceptional cases, examples shouldn’t run, since they can’t work.
For example, a function that connects to a private webservice. In
such cases, we can add
# doctest: +SKIP
at the end of the lines that should not run - In some cases, as it is not possible to display the result as it may
involve the styling of a table, it will be necessary to skip the
test (ensuring that it is happening correctly) or use the tag
# doctest: +ELLIPSIS
Observation
In some cases it’ll be necessary to use # doctest: +SKIP
and later in another use or in this same issue, add images for some results that cannot be displayed, such as stylizations and color addition (this was dealt with in another issue).
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
TST: Fix doctest in _parse_latex_table_styles · Issue #42674 ...
To test the docstring of an object, the next command can be run: python -m pytest --doctest-modules pandas/core/frame.py::pandas.core.frame.DataFrame.info.
Read more >doctest — Test interactive Python examples — Python 3.11.1 ...
The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they...
Read more >Function Doctests
Function Doctests. Doctests are a very handy feature for automatically testing a function by looking at its inputs and outputs.
Read more >Creating Python Function docstrings and Running doctests
What information goes into a Python function docstring? How can you create tests within your docstrings, that can be checked with doctests ?...
Read more >Python's doctest: Document and Test Your Code at Once
Runs the executable code like regular Python code; Compares the execution result with the expected result. The doctest framework searches for ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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. Some of the the doc tests as is has the advantages of being editable by devs and visible to users, but the disadvantage of failing a doc test.
The solution here, as is with many styler doc tests is to skip the doc test, where appropriate.
If no output is provided then considerations should be made as to either:
For example
background_gradient
uses images since the examples produce very specific visual effects that need to be demonstrated, buthide_index
does not need such graphics, only textual representation.@attack68 Great observations. I’ll put a link to the
Table visualization
for these items. Example below: