From 24d35926b79dac9fe5d71cc122f45fa27683019d Mon Sep 17 00:00:00 2001 From: Anh Trinh Date: Thu, 7 Mar 2024 20:03:18 +0100 Subject: [PATCH 1/3] Validate docstring error code --- ci/code_checks.sh | 4 ++-- scripts/validate_docstrings.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 5bbad800b7aa9..23cd35cad3287 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, 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 + $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 RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Partially validate docstrings (PR02)' ; echo $MSG diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index a4d53d360a12b..cc026a0202322 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.", + "GL11": "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("GL11")) 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, From 34ef60bdd2906d263bf5dd411232240f41f3a9d5 Mon Sep 17 00:00:00 2001 From: Anh Trinh Date: Thu, 7 Mar 2024 21:08:20 +0100 Subject: [PATCH 2/3] Rename error code --- ci/code_checks.sh | 4 ++-- scripts/validate_docstrings.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 23cd35cad3287..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, 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 - $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 + 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/validate_docstrings.py b/scripts/validate_docstrings.py index cc026a0202322..6138afba4d880 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -57,7 +57,7 @@ ERROR_MSGS = { "GL04": "Private classes ({mentioned_private_classes}) should not be " "mentioned in public docstrings", - "GL11": "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} " @@ -277,7 +277,7 @@ def pandas_validate(func_name: str): ) if doc.non_hyphenated_array_like(): - result["errors"].append(pandas_error("GL11")) + result["errors"].append(pandas_error("PD01")) plt.close("all") return result From 60840d133712a1dee84516e93b8d3289270a01bc Mon Sep 17 00:00:00 2001 From: Anh Trinh Date: Thu, 7 Mar 2024 21:15:07 +0100 Subject: [PATCH 3/3] Fix tests --- scripts/tests/test_validate_docstrings.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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,