Description
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