diff --git a/ci/code_checks.sh b/ci/code_checks.sh index a08a0cbd87383..95362dbbfa5bb 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, EX02, EX04, GL01, GL02, GL03, GL04, GL05, GL06, GL07, GL09, GL10, PR03, PR04, PR05, PR06, PR08, PR09, PR10, RT01, RT02, RT04, RT05, SA02, SA03, SA04, SS01, SS02, SS03, SS04, SS05, SS06)' ; echo $MSG - $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01,EX02,EX04,GL01,GL02,GL03,GL04,GL05,GL06,GL07,GL09,GL10,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT02,RT04,RT05,SA02,SA03,SA04,SS01,SS02,SS03,SS04,SS05,SS06 + MSG='Validate docstrings (EX01, EX04, GL01, GL02, GL03, GL04, GL05, GL06, GL07, GL09, GL10, PR03, PR04, PR05, PR06, PR08, PR09, PR10, RT01, RT02, RT04, RT05, SA02, SA03, SA04, SS01, SS02, SS03, SS04, SS05, SS06)' ; echo $MSG + $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01,EX04,GL01,GL02,GL03,GL04,GL05,GL06,GL07,GL09,GL10,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT02,RT04,RT05,SA02,SA03,SA04,SS01,SS02,SS03,SS04,SS05,SS06 RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Partially validate docstrings (EX03)' ; echo $MSG diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 02c6808658a33..baa27d14acc8c 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -199,12 +199,6 @@ def test_bad_docstrings(self, capsys, klass, func, msgs) -> None: for msg in msgs: assert msg in " ".join([err[1] for err in result["errors"]]) - def test_leftover_files_raises(self) -> None: - with pytest.raises(Exception, match="The following files"): - validate_docstrings.pandas_validate( - self._import_path(klass="BadDocstrings", func="leftover_files") - ) - def test_validate_all_ignore_functions(self, monkeypatch) -> None: monkeypatch.setattr( validate_docstrings, diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 76d64d27b221c..53c67b7df928b 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -18,7 +18,6 @@ import argparse import doctest import importlib -import io import json import os import pathlib @@ -28,15 +27,12 @@ import matplotlib import matplotlib.pyplot as plt -import numpy from numpydoc.docscrape import get_doc_object from numpydoc.validate import ( Validator, validate, ) -import pandas - # With template backend, matplotlib plots nothing matplotlib.use("template") @@ -63,7 +59,6 @@ "GL05": "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.", - "EX02": "Examples do not pass tests:\n{doctest_log}", "EX03": "flake8 error: line {line_number}, col {col_number}: {error_code} " "{error_message}", "EX04": "Do not import {imported_library}, as it is imported " @@ -167,32 +162,6 @@ def name(self): def mentioned_private_classes(self): return [klass for klass in PRIVATE_CLASSES if klass in self.raw_doc] - @property - def examples_errors(self): - flags = doctest.NORMALIZE_WHITESPACE | doctest.IGNORE_EXCEPTION_DETAIL - finder = doctest.DocTestFinder() - runner = doctest.DocTestRunner(optionflags=flags) - context = {"np": numpy, "pd": pandas} - error_msgs = "" - current_dir = set(os.listdir()) - for test in finder.find(self.raw_doc, self.name, globs=context): - f = io.StringIO() - runner.run(test, out=f.write) - error_msgs += f.getvalue() - leftovers = set(os.listdir()).difference(current_dir) - if leftovers: - for leftover in leftovers: - path = pathlib.Path(leftover).resolve() - if path.is_dir(): - path.rmdir() - elif path.is_file(): - path.unlink(missing_ok=True) - raise Exception( - f"The following files were leftover from the doctest: " - f"{leftovers}. Please use # doctest: +SKIP" - ) - return error_msgs - @property def examples_source_code(self): lines = doctest.DocTestParser().get_examples(self.raw_doc) @@ -290,12 +259,6 @@ def pandas_validate(func_name: str): result["examples_errs"] = "" if doc.examples: - result["examples_errs"] = doc.examples_errors - if result["examples_errs"]: - result["errors"].append( - pandas_error("EX02", doctest_log=result["examples_errs"]) - ) - for error_code, error_message, line_number, col_number in doc.validate_pep8(): result["errors"].append( pandas_error( @@ -429,9 +392,6 @@ def header(title, width=80, char="#") -> str: if result["errors"]: sys.stderr.write(f'{len(result["errors"])} Errors found for `{func_name}`:\n') for err_code, err_desc in result["errors"]: - if err_code == "EX02": # Failing examples are printed at the end - sys.stderr.write("\tExamples do not pass tests\n") - continue sys.stderr.write(f"\t{err_desc}\n") else: sys.stderr.write(f'Docstring for "{func_name}" correct. :)\n')