Skip to content

Commit 90df53d

Browse files
mroeschkepmhatre1
authored andcommitted
DOC: Remove manual doctesting from validate_docstrings (pandas-dev#56871)
1 parent 137389b commit 90df53d

File tree

3 files changed

+2
-48
lines changed

3 files changed

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

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

scripts/tests/test_validate_docstrings.py

-6
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,6 @@ def test_bad_docstrings(self, capsys, klass, func, msgs) -> None:
199199
for msg in msgs:
200200
assert msg in " ".join([err[1] for err in result["errors"]])
201201

202-
def test_leftover_files_raises(self) -> None:
203-
with pytest.raises(Exception, match="The following files"):
204-
validate_docstrings.pandas_validate(
205-
self._import_path(klass="BadDocstrings", func="leftover_files")
206-
)
207-
208202
def test_validate_all_ignore_functions(self, monkeypatch) -> None:
209203
monkeypatch.setattr(
210204
validate_docstrings,

scripts/validate_docstrings.py

-40
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import argparse
1919
import doctest
2020
import importlib
21-
import io
2221
import json
2322
import os
2423
import pathlib
@@ -28,15 +27,12 @@
2827

2928
import matplotlib
3029
import matplotlib.pyplot as plt
31-
import numpy
3230
from numpydoc.docscrape import get_doc_object
3331
from numpydoc.validate import (
3432
Validator,
3533
validate,
3634
)
3735

38-
import pandas
39-
4036
# With template backend, matplotlib plots nothing
4137
matplotlib.use("template")
4238

@@ -63,7 +59,6 @@
6359
"GL05": "Use 'array-like' rather than 'array_like' in docstrings.",
6460
"SA05": "{reference_name} in `See Also` section does not need `pandas` "
6561
"prefix, use {right_reference} instead.",
66-
"EX02": "Examples do not pass tests:\n{doctest_log}",
6762
"EX03": "flake8 error: line {line_number}, col {col_number}: {error_code} "
6863
"{error_message}",
6964
"EX04": "Do not import {imported_library}, as it is imported "
@@ -167,32 +162,6 @@ def name(self):
167162
def mentioned_private_classes(self):
168163
return [klass for klass in PRIVATE_CLASSES if klass in self.raw_doc]
169164

170-
@property
171-
def examples_errors(self):
172-
flags = doctest.NORMALIZE_WHITESPACE | doctest.IGNORE_EXCEPTION_DETAIL
173-
finder = doctest.DocTestFinder()
174-
runner = doctest.DocTestRunner(optionflags=flags)
175-
context = {"np": numpy, "pd": pandas}
176-
error_msgs = ""
177-
current_dir = set(os.listdir())
178-
for test in finder.find(self.raw_doc, self.name, globs=context):
179-
f = io.StringIO()
180-
runner.run(test, out=f.write)
181-
error_msgs += f.getvalue()
182-
leftovers = set(os.listdir()).difference(current_dir)
183-
if leftovers:
184-
for leftover in leftovers:
185-
path = pathlib.Path(leftover).resolve()
186-
if path.is_dir():
187-
path.rmdir()
188-
elif path.is_file():
189-
path.unlink(missing_ok=True)
190-
raise Exception(
191-
f"The following files were leftover from the doctest: "
192-
f"{leftovers}. Please use # doctest: +SKIP"
193-
)
194-
return error_msgs
195-
196165
@property
197166
def examples_source_code(self):
198167
lines = doctest.DocTestParser().get_examples(self.raw_doc)
@@ -290,12 +259,6 @@ def pandas_validate(func_name: str):
290259

291260
result["examples_errs"] = ""
292261
if doc.examples:
293-
result["examples_errs"] = doc.examples_errors
294-
if result["examples_errs"]:
295-
result["errors"].append(
296-
pandas_error("EX02", doctest_log=result["examples_errs"])
297-
)
298-
299262
for error_code, error_message, line_number, col_number in doc.validate_pep8():
300263
result["errors"].append(
301264
pandas_error(
@@ -429,9 +392,6 @@ def header(title, width=80, char="#") -> str:
429392
if result["errors"]:
430393
sys.stderr.write(f'{len(result["errors"])} Errors found for `{func_name}`:\n')
431394
for err_code, err_desc in result["errors"]:
432-
if err_code == "EX02": # Failing examples are printed at the end
433-
sys.stderr.write("\tExamples do not pass tests\n")
434-
continue
435395
sys.stderr.write(f"\t{err_desc}\n")
436396
else:
437397
sys.stderr.write(f'Docstring for "{func_name}" correct. :)\n')

0 commit comments

Comments
 (0)