Skip to content

Validate docstring error code #57767

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
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ fi
### DOCSTRINGS ###
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then

MSG='Validate docstrings (EX01, EX03, EX04, GL01, GL02, GL03, GL04, GL05, GL06, GL07, GL09, GL10, PR03, PR04, PR05, PR06, PR08, PR09, PR10, RT01, RT02, RT04, RT05, SA02, SA03, SA04, SA05, SS01, SS02, SS03, SS04, SS05, SS06)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01,EX03,EX04,GL01,GL02,GL03,GL04,GL05,GL06,GL07,GL09,GL10,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT02,RT04,RT05,SA02,SA03,SA04,SA05,SS01,SS02,SS03,SS04,SS05,SS06
MSG='Validate docstrings (EX01, EX03, EX04, GL01, GL02, GL03, GL04, GL06, GL07, GL09, GL10, PD01, PR03, PR04, PR05, PR06, PR08, PR09, PR10, RT01, RT02, RT04, RT05, SA02, SA03, SA04, SA05, SS01, SS02, SS03, SS04, SS05, SS06)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01,EX03,EX04,GL01,GL02,GL03,GL04,GL06,GL07,GL09,GL10,PD01,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT02,RT04,RT05,SA02,SA03,SA04,SA05,SS01,SS02,SS03,SS04,SS05,SS06
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Partially validate docstrings (PR02)' ; echo $MSG
Expand Down
10 changes: 9 additions & 1 deletion scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ def test_no_exit_status_noerrors_for_validate_all(self, monkeypatch) -> None:
assert exit_status == 0

def test_exit_status_for_validate_all_json(self, monkeypatch) -> None:
print("EXECUTED")
monkeypatch.setattr(
validate_docstrings,
"validate_all",
Expand Down Expand Up @@ -471,6 +470,15 @@ def test_errors_param_filters_errors(self, monkeypatch) -> None:
},
},
)
monkeypatch.setattr(
validate_docstrings,
"ERROR_MSGS",
{
"ER01": "err desc",
"ER02": "err desc",
"ER03": "err desc",
},
)
exit_status = validate_docstrings.main(
func_name=None,
prefix=None,
Expand Down
14 changes: 11 additions & 3 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import matplotlib.pyplot as plt
from numpydoc.docscrape import get_doc_object
from numpydoc.validate import (
ERROR_MSGS as NUMPYDOC_ERROR_MSGS,
Validator,
validate,
)
Expand Down Expand Up @@ -56,7 +57,7 @@
ERROR_MSGS = {
"GL04": "Private classes ({mentioned_private_classes}) should not be "
"mentioned in public docstrings",
"GL05": "Use 'array-like' rather than 'array_like' in docstrings.",
"PD01": "Use 'array-like' rather than 'array_like' in docstrings.",
"SA05": "{reference_name} in `See Also` section does not need `pandas` "
"prefix, use {right_reference} instead.",
"EX03": "flake8 error: line {line_number}, col {col_number}: {error_code} "
Expand Down Expand Up @@ -239,7 +240,6 @@ def pandas_validate(func_name: str):
doc_obj = get_doc_object(func_obj, doc=func_obj.__doc__)
doc = PandasDocstring(func_name, doc_obj)
result = validate(doc_obj)

mentioned_errs = doc.mentioned_private_classes
if mentioned_errs:
result["errors"].append(
Expand Down Expand Up @@ -277,7 +277,7 @@ def pandas_validate(func_name: str):
)

if doc.non_hyphenated_array_like():
result["errors"].append(pandas_error("GL05"))
result["errors"].append(pandas_error("PD01"))

plt.close("all")
return result
Expand Down Expand Up @@ -400,11 +400,19 @@ def header(title, width=80, char="#") -> str:
sys.stderr.write(header("Doctests"))
sys.stderr.write(result["examples_errs"])

def validate_error_codes(errors):
overlapped_errors = set(NUMPYDOC_ERROR_MSGS).intersection(set(ERROR_MSGS))
assert not overlapped_errors, f"{overlapped_errors} is overlapped."
all_errors = set(NUMPYDOC_ERROR_MSGS).union(set(ERROR_MSGS))
nonexistent_errors = set(errors) - all_errors
assert not nonexistent_errors, f"{nonexistent_errors} don't exist."


def main(func_name, prefix, errors, output_format, ignore_deprecated, ignore_functions):
"""
Main entry point. Call the validation for one or for all docstrings.
"""
validate_error_codes(errors)
if func_name is None:
return print_validate_all_results(
prefix,
Expand Down