Skip to content

DOC: Add missing docstring error to validate_docstrings.py #23673

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 1 commit into from
Dec 7, 2018
Merged
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
5 changes: 5 additions & 0 deletions scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ def sections_in_wrong_order(self):
before Examples.
"""

def method_wo_docstrings(self):
pass


class BadSummaries(object):

Expand Down Expand Up @@ -826,6 +829,8 @@ def test_bad_generic_functions(self, func):
('Do not import numpy, as it is imported automatically',)),
('BadGenericDocStrings', 'method',
('Do not import pandas, as it is imported automatically',)),
('BadGenericDocStrings', 'method_wo_docstrings',
("The object does not have a docstring",)),
# See Also tests
('BadSeeAlso', 'prefix_pandas',
('pandas.Series.rename in `See Also` section '
Expand Down
43 changes: 35 additions & 8 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'{allowed_sections}',
'GL07': 'Sections are in the wrong order. Correct order is: '
'{correct_sections}',
'GL08': 'The object does not have a docstring',
'SS01': 'No summary found (a short summary in a single line should be '
'present at the beginning of the docstring)',
'SS02': 'Summary does not start with a capital letter',
Expand Down Expand Up @@ -545,20 +546,24 @@ def validate_pep8(self):
yield from application.guide.stats.statistics_for('')


def validate_one(func_name):
def get_validation_data(doc):
"""
Validate the docstring for the given func_name
Validate the docstring.

Parameters
----------
func_name : function
Function whose docstring will be evaluated (e.g. pandas.read_csv).
doc : Docstring
A Docstring object with the given function name.

Returns
-------
dict
A dictionary containing all the information obtained from validating
the docstring.
tuple
errors : list of tuple
Errors occurred during validation.
warnings : list of tuple
Warnings occurred during validation.
examples_errs : str
Examples usage displayed along the error, otherwise empty string.

Notes
-----
Expand All @@ -585,10 +590,13 @@ def validate_one(func_name):
they are validated, are not documented more than in the source code of this
function.
"""
doc = Docstring(func_name)

errs = []
wrns = []
if not doc.raw_doc:
errs.append(error('GL08'))
return errs, wrns, ''

if doc.start_blank_lines != 1:
errs.append(error('GL01'))
if doc.end_blank_lines != 1:
Expand Down Expand Up @@ -706,7 +714,26 @@ def validate_one(func_name):
for wrong_import in ('numpy', 'pandas'):
if 'import {}'.format(wrong_import) in examples_source_code:
errs.append(error('EX04', imported_library=wrong_import))
return errs, wrns, examples_errs


def validate_one(func_name):
"""
Validate the docstring for the given func_name

Parameters
----------
func_name : function
Function whose docstring will be evaluated (e.g. pandas.read_csv).

Returns
-------
dict
A dictionary containing all the information obtained from validating
the docstring.
"""
doc = Docstring(func_name)
errs, wrns, examples_errs = get_validation_data(doc)
return {'type': doc.type,
'docstring': doc.clean_doc,
'deprecated': doc.deprecated,
Expand Down