From 0a18b8721a35be28b8424ac1e4f6664455a03e9a Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 13 May 2021 14:15:42 -0500 Subject: [PATCH 1/5] DOC: unpin numpydoc, fix validation script #39688 --- environment.yml | 2 +- requirements-dev.txt | 2 +- scripts/validate_docstrings.py | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/environment.yml b/environment.yml index 99ce0d9f9ea01..e905b63b42d0c 100644 --- a/environment.yml +++ b/environment.yml @@ -116,5 +116,5 @@ dependencies: - natsort # DataFrame.sort_values - pip: - git+https://github.com/pydata/pydata-sphinx-theme.git@master - - numpydoc < 1.2 # 2021-02-09 1.2dev breaking CI + - git+https://github.com/numpy/numpydoc.git - pandas-dev-flaker==0.2.0 diff --git a/requirements-dev.txt b/requirements-dev.txt index 6ba867f470f8f..cd29d7a5bf89d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -79,5 +79,5 @@ pyreadstat tabulate>=0.8.3 natsort git+https://github.com/pydata/pydata-sphinx-theme.git@master -numpydoc < 1.2 +git+https://github.com/numpy/numpydoc.git pandas-dev-flaker==0.2.0 diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index d0f32bb554cf9..eaca88c62ffff 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -17,6 +17,7 @@ import doctest import glob import importlib +from io import StringIO import json import os import subprocess @@ -27,11 +28,6 @@ Optional, ) -try: - from io import StringIO -except ImportError: - from cStringIO import StringIO - # 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. @@ -49,7 +45,8 @@ import pandas # isort:skip sys.path.insert(1, os.path.join(BASE_PATH, "doc", "sphinxext")) -from numpydoc.validate import validate, Docstring # isort:skip +from numpydoc.validate import validate, Validator # isort:skip +from numpydoc.docscrape import get_doc_object PRIVATE_CLASSES = ["NDFrame", "IndexOpsMixin"] @@ -145,7 +142,7 @@ def get_api_items(api_doc_fd): previous_line = line -class PandasDocstring(Docstring): +class PandasDocstring(Validator): @property def mentioned_private_classes(self): return [klass for klass in PRIVATE_CLASSES if klass in self.raw_doc] @@ -213,7 +210,9 @@ def pandas_validate(func_name: str): dict Information about the docstring and the errors found. """ - doc = PandasDocstring(func_name) + func_obj = get_doc_object(Validator._load_obj(func_name)) + print(func_name, func_obj._obj) + doc = PandasDocstring(func_obj) result = validate(func_name) mentioned_errs = doc.mentioned_private_classes From ff70167ac02dbf06d69f5d30484558415a016179 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 13 May 2021 14:19:29 -0500 Subject: [PATCH 2/5] clean --- scripts/validate_docstrings.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index eaca88c62ffff..5547481557c80 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -48,7 +48,6 @@ from numpydoc.validate import validate, Validator # isort:skip from numpydoc.docscrape import get_doc_object - PRIVATE_CLASSES = ["NDFrame", "IndexOpsMixin"] ERROR_MSGS = { "GL04": "Private classes ({mentioned_private_classes}) should not be " @@ -211,7 +210,6 @@ def pandas_validate(func_name: str): Information about the docstring and the errors found. """ func_obj = get_doc_object(Validator._load_obj(func_name)) - print(func_name, func_obj._obj) doc = PandasDocstring(func_obj) result = validate(func_name) From 0f516a6335b1474c66a83873023145e8c77e86b6 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 22 Jun 2021 16:30:26 -0500 Subject: [PATCH 3/5] fix script --- scripts/validate_docstrings.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 67689efbb79c6..0a3f181458fed 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -152,10 +152,17 @@ def examples_errors(self): runner = doctest.DocTestRunner(optionflags=flags) context = {"np": numpy, "pd": pandas} error_msgs = "" - for test in finder.find(self.raw_doc, self.name, globs=context): - f = StringIO() - runner.run(test, out=f.write) - error_msgs += f.getvalue() + name = None + try: + name = self.name + except AttributeError: + if not isinstance(self.obj, property): + name = type(self.obj).__name__ + if name is not None: + for test in finder.find(self.raw_doc, name, globs=context): + f = StringIO() + runner.run(test, out=f.write) + error_msgs += f.getvalue() return error_msgs @property From 4b48cb3a0da08fed420e849df0d621a9e02caf5b Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 22 Jun 2021 20:12:01 -0500 Subject: [PATCH 4/5] fix tests --- scripts/tests/test_validate_docstrings.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 46cfae8e31208..224669937d2df 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -305,8 +305,12 @@ class TestPandasDocstringClass: "name", ["pandas.Series.str.isdecimal", "pandas.Series.str.islower"] ) def test_encode_content_write_to_file(self, name): + from numpydoc.docscrape import get_doc_object + from numpydoc.validate import Validator + # GH25466 - docstr = validate_docstrings.PandasDocstring(name).validate_pep8() + func_obj = get_doc_object(Validator._load_obj(name)) + docstr = validate_docstrings.PandasDocstring(func_obj).validate_pep8() # the list of pep8 errors should be empty assert not list(docstr) From 2efd84a8040c108f90c42a2326c93c767db59204 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 8 Jul 2021 11:24:50 -0500 Subject: [PATCH 5/5] fix import --- scripts/validate_docstrings.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 4e4a9e471937a..1b596e8f88cdb 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -36,7 +36,6 @@ import pandas - # With template backend, matplotlib plots nothing matplotlib.use("template") @@ -154,7 +153,7 @@ def examples_errors(self): name = type(self.obj).__name__ if name is not None: for test in finder.find(self.raw_doc, name, globs=context): - f = StringIO() + f = io.StringIO() runner.run(test, out=f.write) error_msgs += f.getvalue() return error_msgs