Skip to content

STYLE: Fix errors in doctests #51341

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
datapythonista opened this issue Feb 12, 2023 · 3 comments · Fixed by #51356
Closed

STYLE: Fix errors in doctests #51341

datapythonista opened this issue Feb 12, 2023 · 3 comments · Fixed by #51356
Assignees
Labels
Code Style Code style, linting, code_checks Docs good first issue

Comments

@datapythonista
Copy link
Member

xref #22900

We'd like to validate that the examples in our documentation (docstrings) follow PEP-8. For that, we need to start by fixing the existing errors, so the validation doesn't fail when we add it.

To find the list of errors, we need to add F821 to the list of flake8 errors to ignore in setup.cfg (F821 is a tricky error, see #22900). The list of errors is next, the command should report zero problems, so errors need to be fixed:

$ flake8 --doctests pandas/
pandas/core/generic.py:3343:33: F721 syntax error in doctest
pandas/errors/__init__.py:458:17: F721 syntax error in doctest
pandas/errors/__init__.py:461:17: F721 syntax error in doctest
pandas/errors/__init__.py:568:9: F401 'pandas.io.stata.StataReader' imported but unused
pandas/errors/__init__.py:571:30: F721 syntax error in doctest
pandas/io/formats/style.py:966:19: F721 syntax error in doctest
pandas/io/formats/style.py:987:19: F721 syntax error in doctest
pandas/io/formats/style.py:1874:23: F721 syntax error in doctest
pandas/io/formats/style.py:1882:30: F721 syntax error in doctest
pandas/io/formats/style.py:1884:23: F721 syntax error in doctest
pandas/io/formats/style.py:2787:23: F721 syntax error in doctest
pandas/io/formats/style.py:2793:23: F721 syntax error in doctest
pandas/io/formats/style.py:2799:23: F721 syntax error in doctest
pandas/io/formats/style.py:2805:23: F721 syntax error in doctest
pandas/io/formats/style.py:2811:23: F721 syntax error in doctest
pandas/io/formats/style.py:2820:23: F721 syntax error in doctest
pandas/io/formats/style.py:3508:21: F721 syntax error in doctest
pandas/io/formats/style_render.py:1081:17: F721 syntax error in doctest

We need to see what's the problem in each case, but seems like in some cases it's the lack of parenthesis in multiline code. For example, this is invalid (both lines are independent for the interpreter, and the second has invalid syntax):

>>> df.style.applymap(lambda x: 'background-color: blueGreenRed;')    
...         .to_excel('styled.xlsx') # doctest: +SKIP

This can be fixed by adding parenthesis surrounding all lines in the statement:

>>> (df.style.applymap(lambda x: 'background-color: blueGreenRed;')    
...          .to_excel('styled.xlsx')) # doctest: +SKIP

CC: @jbrockmendel

@datapythonista datapythonista added Docs Code Style Code style, linting, code_checks good first issue labels Feb 12, 2023
@kkangs0226
Copy link
Contributor

take

@VitthalGupta
Copy link

I'll also take it

@Arthavruksha
Copy link

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks Docs good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants