Description
It'd be great to start linting the doctests (validate the docstring examples for pep8 issues).
To start with core/generic.py
, core/series.py
and core/frame.py
, I created the next issues to address the current errors: #22892, #22893, #22894, #22895, #22896, #22897 and #22898.
After those are fixed, the only error that will remain in these files is F821 undefined name 'pd'
. I checked for simple ways to avoid it, but I don't think we can prepend code for flake8 (like what we do in sphinx). So, the solutions I see are:
- Add
import pandas as pd
(or even betterimport pandas
) to every example - Do not lint the doctests
- Ignore
F821
from the doctest linting (this will also ignore errors likedf + 1
where df is not defined, as it's also anF821
error). - Implement a way to
grep -v
those exact errors, and change the exit code offlake8
based on that, so the linting passes when the output is clean after filtering these errors
I know this has been discussed before, and I'm not sure if anyone else besides me is in favor of option 1. But I think it's worth considering it again in the context of linting doctests. Option 1 has the advantage that the examples are self-contained (they can be copy-pasted, or in the future we can even add a button to open them in binder, or something similar).