Skip to content

CLN: clean doc validation script #42436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,26 @@

import argparse
import doctest
import glob
import importlib
import io
import json
import os
import pathlib
import subprocess
import sys
import tempfile

try:
from io import StringIO
except ImportError:
from cStringIO import StringIO
import matplotlib
import matplotlib.pyplot as plt
import numpy
from numpydoc.validate import (
Docstring,
validate,
)

# Template backend makes matplotlib to not plot anything. This is useful
# to avoid that plot windows are open from the doctests while running the
# script. Setting here before matplotlib is loaded.
# We don't warn for the number of open plots, as none is actually being opened
os.environ["MPLBACKEND"] = "Template"
import matplotlib # isort:skip
import pandas

matplotlib.rc("figure", max_open_warning=10000)

import numpy # isort:skip

BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

sys.path.insert(0, os.path.join(BASE_PATH))
import pandas # isort:skip

sys.path.insert(1, os.path.join(BASE_PATH, "doc", "sphinxext"))
from numpydoc.validate import validate, Docstring # isort:skip
# With template backend, matplotlib plots nothing
matplotlib.use("template")


PRIVATE_CLASSES = ["NDFrame", "IndexOpsMixin"]
Expand Down Expand Up @@ -157,7 +146,7 @@ def examples_errors(self):
context = {"np": numpy, "pd": pandas}
error_msgs = ""
for test in finder.find(self.raw_doc, self.name, globs=context):
f = StringIO()
f = io.StringIO()
runner.run(test, out=f.write)
error_msgs += f.getvalue()
return error_msgs
Expand Down Expand Up @@ -263,6 +252,7 @@ def pandas_validate(func_name: str):
if doc.non_hyphenated_array_like():
result["errors"].append(pandas_error("GL05"))

plt.close("all")
return result


Expand All @@ -288,13 +278,14 @@ def validate_all(prefix, ignore_deprecated=False):
result = {}
seen = {}

api_doc_fnames = os.path.join(BASE_PATH, "doc", "source", "reference", "*.rst")
base_path = pathlib.Path(__file__).parent.parent
api_doc_fnames = pathlib.Path(base_path, "doc", "source", "reference")
api_items = []
for api_doc_fname in glob.glob(api_doc_fnames):
for api_doc_fname in api_doc_fnames.glob("*.rst"):
with open(api_doc_fname) as f:
api_items += list(get_api_items(f))

for func_name, func_obj, section, subsection in api_items:
for func_name, _, section, subsection in api_items:
if prefix and not func_name.startswith(prefix):
continue
doc_info = pandas_validate(func_name)
Expand Down