Skip to content

Commit f82982c

Browse files
aqurillaPingviinituutti
authored andcommitted
DOC: Fix and validate that deprecation directive is in the right position in the docstrings (pandas-dev#24188)
1 parent 507f225 commit f82982c

File tree

8 files changed

+37
-18
lines changed

8 files changed

+37
-18
lines changed

ci/code_checks.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ fi
212212
### DOCSTRINGS ###
213213
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
214214

215-
MSG='Validate docstrings (GL06, SS04, PR03, PR05, EX04)' ; echo $MSG
216-
$BASE_DIR/scripts/validate_docstrings.py --format=azure --errors=GL06,SS04,PR03,PR05,EX04
215+
MSG='Validate docstrings (GL09, GL06, SS04, PR03, PR05, EX04)' ; echo $MSG
216+
$BASE_DIR/scripts/validate_docstrings.py --format=azure --errors=GL09,GL06,SS04,PR03,PR05,EX04
217217
RET=$(($RET + $?)) ; echo $MSG "DONE"
218218

219219
fi

pandas/core/generic.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10039,9 +10039,7 @@ def nanptp(values, axis=0, skipna=True):
1003910039
cls, 'ptp', name, name2, axis_descr,
1004010040
"""Returns the difference between the maximum value and the
1004110041
minimum value in the object. This is the equivalent of the
10042-
``numpy.ndarray`` method ``ptp``.
10043-
10044-
.. deprecated:: 0.24.0
10042+
``numpy.ndarray`` method ``ptp``.\n\n.. deprecated:: 0.24.0
1004510043
Use numpy.ptp instead""",
1004610044
nanptp)
1004710045

pandas/core/indexes/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2113,12 +2113,12 @@ def get_duplicates(self):
21132113
"""
21142114
Extract duplicated index elements.
21152115
2116-
Returns a sorted list of index elements which appear more than once in
2117-
the index.
2118-
21192116
.. deprecated:: 0.23.0
21202117
Use idx[idx.duplicated()].unique() instead
21212118
2119+
Returns a sorted list of index elements which appear more than once in
2120+
the index.
2121+
21222122
Returns
21232123
-------
21242124
array-like

pandas/core/indexes/multi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1484,11 +1484,11 @@ def to_hierarchical(self, n_repeat, n_shuffle=1):
14841484
Return a MultiIndex reshaped to conform to the
14851485
shapes given by n_repeat and n_shuffle.
14861486
1487+
.. deprecated:: 0.24.0
1488+
14871489
Useful to replicate and rearrange a MultiIndex for combination
14881490
with another Index with n_repeat items.
14891491
1490-
.. deprecated:: 0.24.0
1491-
14921492
Parameters
14931493
----------
14941494
n_repeat : int

pandas/core/series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1083,12 +1083,12 @@ def set_value(self, label, value, takeable=False):
10831083
"""
10841084
Quickly set single value at passed label.
10851085
1086-
If label is not contained, a new object is created with the label
1087-
placed at the end of the result index.
1088-
10891086
.. deprecated:: 0.21.0
10901087
Please use .at[] or .iat[] accessors.
10911088
1089+
If label is not contained, a new object is created with the label
1090+
placed at the end of the result index.
1091+
10921092
Parameters
10931093
----------
10941094
label : object

pandas/io/stata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@
119119
_data_method_doc = """\
120120
Reads observations from Stata file, converting them into a dataframe
121121
122-
.. deprecated::
123-
This is a legacy method. Use `read` in new code.
122+
.. deprecated::
123+
This is a legacy method. Use `read` in new code.
124124
125125
Parameters
126126
----------

scripts/tests/test_validate_docstrings.py

+14
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ def sections_in_wrong_order(self):
407407
before Examples.
408408
"""
409409

410+
def deprecation_in_wrong_order(self):
411+
"""
412+
This docstring has the deprecation warning in the wrong order.
413+
414+
This is the extended summary. The correct order should be
415+
summary, deprecation warning, extended summary.
416+
417+
.. deprecated:: 1.0
418+
This should generate an error as it needs to go before
419+
extended summary.
420+
"""
421+
410422
def method_wo_docstrings(self):
411423
pass
412424

@@ -772,6 +784,8 @@ def test_bad_generic_functions(self, func):
772784
('BadGenericDocStrings', 'sections_in_wrong_order',
773785
('Sections are in the wrong order. Correct order is: Parameters, '
774786
'See Also, Examples',)),
787+
('BadGenericDocStrings', 'deprecation_in_wrong_order',
788+
('Deprecation warning should precede extended summary',)),
775789
('BadSeeAlso', 'desc_no_period',
776790
('Missing period at end of description for See Also "Series.iloc"',)),
777791
('BadSeeAlso', 'desc_first_letter_lowercase',

scripts/validate_docstrings.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
'GL07': 'Sections are in the wrong order. Correct order is: '
8080
'{correct_sections}',
8181
'GL08': 'The object does not have a docstring',
82+
'GL09': 'Deprecation warning should precede extended summary',
8283
'SS01': 'No summary found (a short summary in a single line should be '
8384
'present at the beginning of the docstring)',
8485
'SS02': 'Summary does not start with a capital letter',
@@ -492,12 +493,14 @@ def first_line_ends_in_dot(self):
492493
if self.doc:
493494
return self.doc.split('\n')[0][-1] == '.'
494495

496+
@property
497+
def deprecated_with_directive(self):
498+
return '.. deprecated:: ' in (self.summary + self.extended_summary)
499+
495500
@property
496501
def deprecated(self):
497-
pattern = re.compile('.. deprecated:: ')
498502
return (self.name.startswith('pandas.Panel')
499-
or bool(pattern.search(self.summary))
500-
or bool(pattern.search(self.extended_summary)))
503+
or self.deprecated_with_directive)
501504

502505
@property
503506
def mentioned_private_classes(self):
@@ -625,6 +628,10 @@ def get_validation_data(doc):
625628
errs.append(error('GL07',
626629
correct_sections=', '.join(correct_order)))
627630

631+
if (doc.deprecated_with_directive
632+
and not doc.extended_summary.startswith('.. deprecated:: ')):
633+
errs.append(error('GL09'))
634+
628635
if not doc.summary:
629636
errs.append(error('SS01'))
630637
else:

0 commit comments

Comments
 (0)