Skip to content

TST: Fix doctests in style.py #42759

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
Leonardofreua opened this issue Jul 28, 2021 · 5 comments · Fixed by #42783
Closed

TST: Fix doctests in style.py #42759

Leonardofreua opened this issue Jul 28, 2021 · 5 comments · Fixed by #42783
Assignees
Labels
CI Continuous Integration Docs Styler conditional formatting using DataFrame.style
Milestone

Comments

@Leonardofreua
Copy link
Contributor

Leonardofreua commented Jul 28, 2021

tl;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 dataset df 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).

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

take

@rhshadrach rhshadrach added Styler conditional formatting using DataFrame.style CI Continuous Integration and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 28, 2021
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Jul 28, 2021
@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.
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:

  • skip it: no output is required in the context.
  • add a textual output and skip the test.
  • add an image output and skip the test.

For example background_gradient uses images since the examples produce very specific visual effects that need to be demonstrated, but hide_index does not need such graphics, only textual representation.

@Leonardofreua
Copy link
Contributor Author

@attack68 Great observations. I think that all doctests I found in the style.py file fit the points you cited.

The methods I have noticed that will need images in your doctests are below:

  • apply()
  • applymap()
  • set_table_styles() maybe?
  • set_properties()
  • pipe()

@attack68
Copy link
Contributor

attack68 commented Jul 28, 2021

@attack68 Great observations. I think that all doctests I found in the style.py file fit the points you cited.

The methods I have noticed that will need images in your doctests are below:

  • apply()
  • applymap()
  • set_table_styles() maybe?
  • set_properties()
  • pipe()

all of those (except pipe) are extensively covered in the table visualization user guide. It might be more advantageous to redirect users to that page.

The background gradient, in my opinion, is an exception because its docstring shows different combinations of keyword arguments which have different effects, which are not covered in the user guide.

pipe is really functional programming and it might suit to just use textual examples.

@Leonardofreua
Copy link
Contributor Author

Leonardofreua commented Jul 28, 2021

@attack68 Great observations. I'll put a link to the Table visualization for these items. Example below:

image

@jreback jreback modified the milestones: Contributions Welcome, 1.4 Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration Docs Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants