Skip to content

DOC: Validate that See Also section items do not contain the pandas. prefix #23145

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 9 commits into from
Oct 27, 2018
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