diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 5bbad800b7aa9..c3fe73acabcbf 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -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 diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index baa27d14acc8c..ea44bd3fcc4cf 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -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", @@ -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, diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index a4d53d360a12b..6138afba4d880 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -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, ) @@ -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} " @@ -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( @@ -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 @@ -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,