Skip to content

Commit 5a990cb

Browse files
tqa236pmhatre1
authored andcommitted
Validate docstring error code (pandas-dev#57767)
* Validate docstring error code * Rename error code * Fix tests
1 parent 7d2af5c commit 5a990cb

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

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, 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
69+
$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
7070
RET=$(($RET + $?)) ; echo $MSG "DONE"
7171

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

scripts/tests/test_validate_docstrings.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ def test_no_exit_status_noerrors_for_validate_all(self, monkeypatch) -> None:
420420
assert exit_status == 0
421421

422422
def test_exit_status_for_validate_all_json(self, monkeypatch) -> None:
423-
print("EXECUTED")
424423
monkeypatch.setattr(
425424
validate_docstrings,
426425
"validate_all",
@@ -471,6 +470,15 @@ def test_errors_param_filters_errors(self, monkeypatch) -> None:
471470
},
472471
},
473472
)
473+
monkeypatch.setattr(
474+
validate_docstrings,
475+
"ERROR_MSGS",
476+
{
477+
"ER01": "err desc",
478+
"ER02": "err desc",
479+
"ER03": "err desc",
480+
},
481+
)
474482
exit_status = validate_docstrings.main(
475483
func_name=None,
476484
prefix=None,

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+
"PD01": "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("PD01"))
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)