Skip to content

DOC/STYLE: Fix "F821 undefined name 'pd'" errors #22900

Open
@datapythonista

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:

  1. Add import pandas as pd (or even better import pandas) to every example
  2. Do not lint the doctests
  3. Ignore F821 from the doctest linting (this will also ignore errors like df + 1 where df is not defined, as it's also an F821 error).
  4. Implement a way to grep -v those exact errors, and change the exit code of flake8 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).

Metadata

Assignees

No one assigned

    Labels

    Code StyleCode style, linting, code_checksDocsNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions