Skip to content

Commit

Permalink
DOC: Validate that See Also section items do not contain the pandas. …
Browse files Browse the repository at this point in the history
…prefix (pandas-dev#23145)
  • Loading branch information
thoo authored and WillAyd committed Oct 27, 2018
1 parent 051f4a2 commit da9d851
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 deletions.
71 changes: 43 additions & 28 deletions scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,33 +334,6 @@ def method(self, foo=None, bar=None):
pass


class BadSeeAlso(object):

def desc_no_period(self):
"""
Return the first 5 elements of the Series.
See Also
--------
Series.tail : Return the last 5 elements of the Series.
Series.iloc : Return a slice of the elements in the Series,
which can also be used to return the first or last n
"""
pass

def desc_first_letter_lowercase(self):
"""
Return the first 5 elements of the Series.
See Also
--------
Series.tail : return the last 5 elements of the Series.
Series.iloc : Return a slice of the elements in the Series,
which can also be used to return the first or last n.
"""
pass


class BadSummaries(object):

def wrong_line(self):
Expand Down Expand Up @@ -573,6 +546,44 @@ def no_punctuation(self):
return "Hello world!"


class BadSeeAlso(object):

def desc_no_period(self):
"""
Return the first 5 elements of the Series.
See Also
--------
Series.tail : Return the last 5 elements of the Series.
Series.iloc : Return a slice of the elements in the Series,
which can also be used to return the first or last n
"""
pass

def desc_first_letter_lowercase(self):
"""
Return the first 5 elements of the Series.
See Also
--------
Series.tail : return the last 5 elements of the Series.
Series.iloc : Return a slice of the elements in the Series,
which can also be used to return the first or last n.
"""
pass

def prefix_pandas(self):
"""
Have `pandas` prefix in See Also section.
See Also
--------
pandas.Series.rename : Alter Series index labels or name.
DataFrame.head : The first `n` rows of the caller object.
"""
pass


class TestValidator(object):

def _import_path(self, klass=None, func=None):
Expand Down Expand Up @@ -688,7 +699,11 @@ def test_bad_generic_functions(self, func):
pytest.param('BadReturns', 'no_description', ('foo',),
marks=pytest.mark.xfail),
pytest.param('BadReturns', 'no_punctuation', ('foo',),
marks=pytest.mark.xfail)
marks=pytest.mark.xfail),
# See Also tests
('BadSeeAlso', 'prefix_pandas',
('pandas.Series.rename in `See Also` section '
'does not need `pandas` prefix',))
])
def test_bad_examples(self, capsys, klass, func, msgs):
result = validate_one(self._import_path(klass=klass, func=func)) # noqa:F821
Expand Down
5 changes: 4 additions & 1 deletion scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,10 @@ def validate_one(func_name):
else:
errs.append('Missing description for '
'See Also "{}" reference'.format(rel_name))

if rel_name.startswith('pandas.'):
errs.append('{} in `See Also` section does not '
'need `pandas` prefix, use {} instead.'
.format(rel_name, rel_name[len('pandas.'):]))
for line in doc.raw_doc.splitlines():
if re.match("^ *\t", line):
errs.append('Tabs found at the start of line "{}", '
Expand Down

0 comments on commit da9d851

Please sign in to comment.