Skip to content

Commit 24d3592

Browse files
committed
Validate docstring error code
1 parent c9f876c commit 24d3592

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Diff for: ci/code_checks.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ fi
6565
### DOCSTRINGS ###
6666
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
6767

68-
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
69-
$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
68+
MSG='Validate docstrings (EX01, EX03, EX04, GL01, GL02, GL03, GL04, GL11, 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
69+
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01,EX03,EX04,GL01,GL02,GL03,GL04,GL11,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
7070
RET=$(($RET + $?)) ; echo $MSG "DONE"
7171

7272
MSG='Partially validate docstrings (PR02)' ; echo $MSG

Diff for: scripts/validate_docstrings.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import matplotlib.pyplot as plt
3030
from numpydoc.docscrape import get_doc_object
3131
from numpydoc.validate import (
32+
ERROR_MSGS as NUMPYDOC_ERROR_MSGS,
3233
Validator,
3334
validate,
3435
)
@@ -56,7 +57,7 @@
5657
ERROR_MSGS = {
5758
"GL04": "Private classes ({mentioned_private_classes}) should not be "
5859
"mentioned in public docstrings",
59-
"GL05": "Use 'array-like' rather than 'array_like' in docstrings.",
60+
"GL11": "Use 'array-like' rather than 'array_like' in docstrings.",
6061
"SA05": "{reference_name} in `See Also` section does not need `pandas` "
6162
"prefix, use {right_reference} instead.",
6263
"EX03": "flake8 error: line {line_number}, col {col_number}: {error_code} "
@@ -239,7 +240,6 @@ def pandas_validate(func_name: str):
239240
doc_obj = get_doc_object(func_obj, doc=func_obj.__doc__)
240241
doc = PandasDocstring(func_name, doc_obj)
241242
result = validate(doc_obj)
242-
243243
mentioned_errs = doc.mentioned_private_classes
244244
if mentioned_errs:
245245
result["errors"].append(
@@ -277,7 +277,7 @@ def pandas_validate(func_name: str):
277277
)
278278

279279
if doc.non_hyphenated_array_like():
280-
result["errors"].append(pandas_error("GL05"))
280+
result["errors"].append(pandas_error("GL11"))
281281

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

403+
def validate_error_codes(errors):
404+
overlapped_errors = set(NUMPYDOC_ERROR_MSGS).intersection(set(ERROR_MSGS))
405+
assert not overlapped_errors, f"{overlapped_errors} is overlapped."
406+
all_errors = set(NUMPYDOC_ERROR_MSGS).union(set(ERROR_MSGS))
407+
nonexistent_errors = set(errors) - all_errors
408+
assert not nonexistent_errors, f"{nonexistent_errors} don't exist."
409+
403410

404411
def main(func_name, prefix, errors, output_format, ignore_deprecated, ignore_functions):
405412
"""
406413
Main entry point. Call the validation for one or for all docstrings.
407414
"""
415+
validate_error_codes(errors)
408416
if func_name is None:
409417
return print_validate_all_results(
410418
prefix,

0 commit comments

Comments
 (0)