Skip to content

DOC: unpin numpydoc, fix validation script #39688 #41456

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 16 additions & 8 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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 "
Expand Down Expand Up @@ -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]
Expand All @@ -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__
Comment on lines +151 to +153
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't covered by any of the tests in scripts/validate_docstrings.py - when could it happen?

if name is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise, none of the tests cover when name is None - when could that happen?

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
Expand Down Expand Up @@ -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
Expand Down