Skip to content

Commit ef59fd5

Browse files
committed
Validate docstring error code
1 parent c9f876c commit ef59fd5

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
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-7
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
import matplotlib
2929
import matplotlib.pyplot as plt
3030
from numpydoc.docscrape import get_doc_object
31-
from numpydoc.validate import (
32-
Validator,
33-
validate,
34-
)
31+
from numpydoc.validate import Validator, validate, ERROR_MSGS as NUMPYDOC_ERROR_MSGS
3532

3633
# With template backend, matplotlib plots nothing
3734
matplotlib.use("template")
@@ -56,7 +53,7 @@
5653
ERROR_MSGS = {
5754
"GL04": "Private classes ({mentioned_private_classes}) should not be "
5855
"mentioned in public docstrings",
59-
"GL05": "Use 'array-like' rather than 'array_like' in docstrings.",
56+
"GL11": "Use 'array-like' rather than 'array_like' in docstrings.",
6057
"SA05": "{reference_name} in `See Also` section does not need `pandas` "
6158
"prefix, use {right_reference} instead.",
6259
"EX03": "flake8 error: line {line_number}, col {col_number}: {error_code} "
@@ -239,7 +236,6 @@ def pandas_validate(func_name: str):
239236
doc_obj = get_doc_object(func_obj, doc=func_obj.__doc__)
240237
doc = PandasDocstring(func_name, doc_obj)
241238
result = validate(doc_obj)
242-
243239
mentioned_errs = doc.mentioned_private_classes
244240
if mentioned_errs:
245241
result["errors"].append(
@@ -277,7 +273,7 @@ def pandas_validate(func_name: str):
277273
)
278274

279275
if doc.non_hyphenated_array_like():
280-
result["errors"].append(pandas_error("GL05"))
276+
result["errors"].append(pandas_error("GL11"))
281277

282278
plt.close("all")
283279
return result
@@ -400,11 +396,19 @@ def header(title, width=80, char="#") -> str:
400396
sys.stderr.write(header("Doctests"))
401397
sys.stderr.write(result["examples_errs"])
402398

399+
def validate_error_codes(errors):
400+
overlapped_errors = set(NUMPYDOC_ERROR_MSGS).intersection(set(ERROR_MSGS))
401+
assert not overlapped_errors, f"{overlapped_errors} is overlapped."
402+
all_errors = set(NUMPYDOC_ERROR_MSGS).union(set(ERROR_MSGS))
403+
nonexistent_errors = set(errors) - all_errors
404+
assert not nonexistent_errors, f"{nonexistent_errors} don't exist."
405+
403406

404407
def main(func_name, prefix, errors, output_format, ignore_deprecated, ignore_functions):
405408
"""
406409
Main entry point. Call the validation for one or for all docstrings.
407410
"""
411+
validate_error_codes(errors)
408412
if func_name is None:
409413
return print_validate_all_results(
410414
prefix,

0 commit comments

Comments
 (0)