Skip to content

Commit a4a0b9f

Browse files
getschompPingviinituutti
authored andcommitted
DOC: Add docstring validations for "See Also" section (pandas-dev#23143)
1 parent 40ca91a commit a4a0b9f

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

scripts/tests/test_validate_docstrings.py

+32
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,33 @@ 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+
337364
class BadSummaries(object):
338365

339366
def wrong_line(self):
@@ -608,6 +635,11 @@ def test_bad_generic_functions(self, func):
608635
assert errors
609636

610637
@pytest.mark.parametrize("klass,func,msgs", [
638+
# See Also tests
639+
('BadSeeAlso', 'desc_no_period',
640+
('Missing period at end of description for See Also "Series.iloc"',)),
641+
('BadSeeAlso', 'desc_first_letter_lowercase',
642+
('should be capitalized for See Also "Series.tail"',)),
611643
# Summary tests
612644
('BadSummaries', 'wrong_line',
613645
('should start in the line immediately after the opening quotes',)),

scripts/validate_docstrings.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,14 @@ def validate_one(func_name):
505505
wrns.append('See Also section not found')
506506
else:
507507
for rel_name, rel_desc in doc.see_also.items():
508-
if not rel_desc:
508+
if rel_desc:
509+
if not rel_desc.endswith('.'):
510+
errs.append('Missing period at end of description for '
511+
'See Also "{}" reference'.format(rel_name))
512+
if not rel_desc[0].isupper():
513+
errs.append('Description should be capitalized for '
514+
'See Also "{}" reference'.format(rel_name))
515+
else:
509516
errs.append('Missing description for '
510517
'See Also "{}" reference'.format(rel_name))
511518

0 commit comments

Comments
 (0)