-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Ensure pandas warnings & exceptions are always documented in API docs #43029
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
Merged
mroeschke
merged 5 commits into
pandas-dev:master
from
mroeschke:doc/pandas_errors_sync
Aug 18, 2021
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a1cd426
DOC: Ensure all pandas.errors are documents in general_utility_functi…
mroeschke 2a41750
Merge remote-tracking branch 'upstream/master' into doc/pandas_errors…
mroeschke faaaa3b
Use ast to check for the errors
mroeschke f526804
Merge remote-tracking branch 'upstream/master' into doc/pandas_errors…
mroeschke 78c01f4
Use pathlib to ensure Windows support
mroeschke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Check that doc/source/reference/general_utility_functions.rst documents | ||
all exceptions and warnings in pandas/errors/__init__.py. | ||
|
||
This is meant to be run as a pre-commit hook - to run it manually, you can do: | ||
|
||
pre-commit run pandas-errors-documented --all-files | ||
""" | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import ast | ||
import sys | ||
from typing import Sequence | ||
|
||
API_PATH = "doc/source/reference/general_utility_functions.rst" | ||
|
||
|
||
def get_defined_errors(content: str) -> set[str]: | ||
errors = set() | ||
for node in ast.walk(ast.parse(content)): | ||
if isinstance(node, ast.ClassDef): | ||
errors.add(node.name) | ||
elif isinstance(node, ast.ImportFrom): | ||
for alias in node.names: | ||
errors.add(alias.name) | ||
return errors | ||
|
||
|
||
def main(argv: Sequence[str] | None = None) -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("path") | ||
args = parser.parse_args(argv) | ||
with open(args.path, encoding="utf-8") as f: | ||
file_errors = get_defined_errors(f.read()) | ||
with open(API_PATH) as f: | ||
doc_errors = { | ||
line.split(".")[1].strip() for line in f.readlines() if "errors" in line | ||
} | ||
missing = file_errors.difference(doc_errors) | ||
if missing: | ||
sys.stdout.write( | ||
f"The follow exceptions and/or warnings are not documented " | ||
f"in {API_PATH}: {missing}" | ||
) | ||
sys.exit(1) | ||
sys.exit(0) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this work if someone runs this hook on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!