Skip to content

Commit da9d851

Browse files
thooWillAyd
authored andcommitted
DOC: Validate that See Also section items do not contain the pandas. prefix (#23145)
1 parent 051f4a2 commit da9d851

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

scripts/tests/test_validate_docstrings.py

+43-28
Original file line numberDiff line numberDiff line change
@@ -334,33 +334,6 @@ def method(self, foo=None, bar=None):
334334
pass
335335

336336

337-
class BadSeeAlso(object):
338-
339-
def desc_no_period(self):
340-
"""
341-
Return the first 5 elements of the Series.
342-
343-
See Also
344-
--------
345-
Series.tail : Return the last 5 elements of the Series.
346-
Series.iloc : Return a slice of the elements in the Series,
347-
which can also be used to return the first or last n
348-
"""
349-
pass
350-
351-
def desc_first_letter_lowercase(self):
352-
"""
353-
Return the first 5 elements of the Series.
354-
355-
See Also
356-
--------
357-
Series.tail : return the last 5 elements of the Series.
358-
Series.iloc : Return a slice of the elements in the Series,
359-
which can also be used to return the first or last n.
360-
"""
361-
pass
362-
363-
364337
class BadSummaries(object):
365338

366339
def wrong_line(self):
@@ -573,6 +546,44 @@ def no_punctuation(self):
573546
return "Hello world!"
574547

575548

549+
class BadSeeAlso(object):
550+
551+
def desc_no_period(self):
552+
"""
553+
Return the first 5 elements of the Series.
554+
555+
See Also
556+
--------
557+
Series.tail : Return the last 5 elements of the Series.
558+
Series.iloc : Return a slice of the elements in the Series,
559+
which can also be used to return the first or last n
560+
"""
561+
pass
562+
563+
def desc_first_letter_lowercase(self):
564+
"""
565+
Return the first 5 elements of the Series.
566+
567+
See Also
568+
--------
569+
Series.tail : return the last 5 elements of the Series.
570+
Series.iloc : Return a slice of the elements in the Series,
571+
which can also be used to return the first or last n.
572+
"""
573+
pass
574+
575+
def prefix_pandas(self):
576+
"""
577+
Have `pandas` prefix in See Also section.
578+
579+
See Also
580+
--------
581+
pandas.Series.rename : Alter Series index labels or name.
582+
DataFrame.head : The first `n` rows of the caller object.
583+
"""
584+
pass
585+
586+
576587
class TestValidator(object):
577588

578589
def _import_path(self, klass=None, func=None):
@@ -688,7 +699,11 @@ def test_bad_generic_functions(self, func):
688699
pytest.param('BadReturns', 'no_description', ('foo',),
689700
marks=pytest.mark.xfail),
690701
pytest.param('BadReturns', 'no_punctuation', ('foo',),
691-
marks=pytest.mark.xfail)
702+
marks=pytest.mark.xfail),
703+
# See Also tests
704+
('BadSeeAlso', 'prefix_pandas',
705+
('pandas.Series.rename in `See Also` section '
706+
'does not need `pandas` prefix',))
692707
])
693708
def test_bad_examples(self, capsys, klass, func, msgs):
694709
result = validate_one(self._import_path(klass=klass, func=func)) # noqa:F821

scripts/validate_docstrings.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,10 @@ def validate_one(func_name):
515515
else:
516516
errs.append('Missing description for '
517517
'See Also "{}" reference'.format(rel_name))
518-
518+
if rel_name.startswith('pandas.'):
519+
errs.append('{} in `See Also` section does not '
520+
'need `pandas` prefix, use {} instead.'
521+
.format(rel_name, rel_name[len('pandas.'):]))
519522
for line in doc.raw_doc.splitlines():
520523
if re.match("^ *\t", line):
521524
errs.append('Tabs found at the start of line "{}", '

0 commit comments

Comments
 (0)