Skip to content

Commit 0f656f7

Browse files
bengineer19datapythonista
authored andcommitted
DOC: Docstring validation ignoring directives in parameters to not report on missing period (#22423)
1 parent 9122952 commit 0f656f7

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

pandas/tests/scripts/test_validate_docstrings.py

+49-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,27 @@ def contains(self, pat, case=True, na=np.nan):
193193
"""
194194
pass
195195

196+
def mode(self, axis, numeric_only):
197+
"""
198+
Ensure sphinx directives don't affect checks for trailing periods.
199+
200+
Parameters
201+
----------
202+
axis : str
203+
Sentence ending in period, followed by single directive.
204+
205+
.. versionchanged:: 0.1.2
206+
207+
numeric_only : boolean
208+
Sentence ending in period, followed by multiple directives.
209+
210+
.. versionadded:: 0.1.2
211+
.. deprecated:: 0.00.0
212+
A multiline description,
213+
which spans another line.
214+
"""
215+
pass
216+
196217

197218
class BadGenericDocStrings(object):
198219
"""Everything here has a bad docstring
@@ -374,6 +395,31 @@ def no_description_period(self, kind):
374395
Doesn't end with a dot
375396
"""
376397

398+
def no_description_period_with_directive(self, kind):
399+
"""
400+
Forgets to add a period, and also includes a directive.
401+
402+
Parameters
403+
----------
404+
kind : str
405+
Doesn't end with a dot
406+
407+
.. versionadded:: 0.00.0
408+
"""
409+
410+
def no_description_period_with_directives(self, kind):
411+
"""
412+
Forgets to add a period, and also includes multiple directives.
413+
414+
Parameters
415+
----------
416+
kind : str
417+
Doesn't end with a dot
418+
419+
.. versionchanged:: 0.00.0
420+
.. deprecated:: 0.00.0
421+
"""
422+
377423
def parameter_capitalization(self, kind):
378424
"""
379425
Forgets to capitalize the description.
@@ -513,7 +559,7 @@ def test_good_class(self):
513559

514560
@pytest.mark.parametrize("func", [
515561
'plot', 'sample', 'random_letters', 'sample_values', 'head', 'head1',
516-
'contains'])
562+
'contains', 'mode'])
517563
def test_good_functions(self, func):
518564
assert validate_one(self._import_path( # noqa: F821
519565
klass='GoodDocStrings', func=func)) == 0
@@ -549,6 +595,8 @@ def test_bad_generic_functions(self, func):
549595
'Parameter "kind: str" has no type')),
550596
('BadParameters', 'no_description_period',
551597
('Parameter "kind" description should finish with "."',)),
598+
('BadParameters', 'no_description_period_with_directive',
599+
('Parameter "kind" description should finish with "."',)),
552600
('BadParameters', 'parameter_capitalization',
553601
('Parameter "kind" description should start with a capital letter',)),
554602
pytest.param('BadParameters', 'blank_lines', ('No error yet?',),

scripts/validate_docstrings.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343

4444
PRIVATE_CLASSES = ['NDFrame', 'IndexOpsMixin']
45+
DIRECTIVES = ['versionadded', 'versionchanged', 'deprecated']
4546

4647

4748
def _load_obj(obj_name):
@@ -234,7 +235,14 @@ def parameter_type(self, param):
234235
return self.doc_parameters[param][0]
235236

236237
def parameter_desc(self, param):
237-
return self.doc_parameters[param][1]
238+
desc = self.doc_parameters[param][1]
239+
# Find and strip out any sphinx directives
240+
for directive in DIRECTIVES:
241+
full_directive = '.. {}'.format(directive)
242+
if full_directive in desc:
243+
# Only retain any description before the directive
244+
desc = desc[:desc.index(full_directive)]
245+
return desc
238246

239247
@property
240248
def see_also(self):

0 commit comments

Comments
 (0)