Skip to content

Commit cd637ec

Browse files
dat-boristm9k1
authored andcommitted
DOC: Improve error message to show correct order (pandas-dev#23652)
1 parent 3be7b2b commit cd637ec

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

scripts/tests/test_validate_docstrings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,8 @@ def test_bad_generic_functions(self, func):
738738
('BadGenericDocStrings', 'unknown_section',
739739
('Found unknown section "Unknown Section".',)),
740740
('BadGenericDocStrings', 'sections_in_wrong_order',
741-
('Wrong order of sections. "See Also" should be located before '
742-
'"Notes"',)),
741+
('Sections are in the wrong order. Correct order is: Parameters, '
742+
'See Also, Examples',)),
743743
('BadSeeAlso', 'desc_no_period',
744744
('Missing period at end of description for See Also "Series.iloc"',)),
745745
('BadSeeAlso', 'desc_first_letter_lowercase',

scripts/validate_docstrings.py

+14-20
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
'whitespace only',
7575
'GL06': 'Found unknown section "{section}". Allowed sections are: '
7676
'{allowed_sections}',
77-
'GL07': 'Wrong order of sections. "{wrong_section}" should be located '
78-
'before "{goes_before}", the right order is: {sorted_sections}',
77+
'GL07': 'Sections are in the wrong order. Correct order is: '
78+
'{correct_sections}',
7979
'SS01': 'No summary found (a short summary in a single line should be '
8080
'present at the beginning of the docstring)',
8181
'SS02': 'Summary does not start with a capital letter',
@@ -601,24 +601,18 @@ def validate_one(func_name):
601601
if re.match("^ *\t", line):
602602
errs.append(error('GL05', line_with_tabs=line.lstrip()))
603603

604-
unseen_sections = list(ALLOWED_SECTIONS)
605-
for section in doc.section_titles:
606-
if section not in ALLOWED_SECTIONS:
607-
errs.append(error('GL06',
608-
section=section,
609-
allowed_sections=', '.join(ALLOWED_SECTIONS)))
610-
else:
611-
if section in unseen_sections:
612-
section_idx = unseen_sections.index(section)
613-
unseen_sections = unseen_sections[section_idx + 1:]
614-
else:
615-
section_idx = ALLOWED_SECTIONS.index(section)
616-
goes_before = ALLOWED_SECTIONS[section_idx + 1]
617-
errs.append(error('GL07',
618-
sorted_sections=' > '.join(ALLOWED_SECTIONS),
619-
wrong_section=section,
620-
goes_before=goes_before))
621-
break
604+
unexpected_sections = [section for section in doc.section_titles
605+
if section not in ALLOWED_SECTIONS]
606+
for section in unexpected_sections:
607+
errs.append(error('GL06',
608+
section=section,
609+
allowed_sections=', '.join(ALLOWED_SECTIONS)))
610+
611+
correct_order = [section for section in ALLOWED_SECTIONS
612+
if section in doc.section_titles]
613+
if correct_order != doc.section_titles:
614+
errs.append(error('GL07',
615+
correct_sections=', '.join(correct_order)))
622616

623617
if not doc.summary:
624618
errs.append(error('SS01'))

0 commit comments

Comments
 (0)