diff --git a/environment.yml b/environment.yml index 9396210da3635..aa5e9505f9901 100644 --- a/environment.yml +++ b/environment.yml @@ -115,7 +115,7 @@ 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 - types-python-dateutil - types-PyMySQL diff --git a/requirements-dev.txt b/requirements-dev.txt index 3bf9084f55419..6fcba7c347608 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -78,7 +78,7 @@ 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 types-python-dateutil types-PyMySQL 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) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 7562895d9db3e..1b596e8f88cdb 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -28,8 +28,9 @@ import matplotlib import matplotlib.pyplot as plt import numpy +from numpydoc.docscrape import get_doc_object from numpydoc.validate import ( - Docstring, + Validator, validate, ) @@ -38,7 +39,6 @@ # With template backend, matplotlib plots nothing matplotlib.use("template") - PRIVATE_CLASSES = ["NDFrame", "IndexOpsMixin"] ERROR_MSGS = { "GL04": "Private classes ({mentioned_private_classes}) should not be " @@ -133,7 +133,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] @@ -145,10 +145,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 = io.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 = io.StringIO() + runner.run(test, out=f.write) + error_msgs += f.getvalue() return error_msgs @property @@ -204,7 +211,8 @@ 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)) + doc = PandasDocstring(func_obj) result = validate(func_name) mentioned_errs = doc.mentioned_private_classes