-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Deprecation directive in Docstrings should be placed before the extended summary #24188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: Deprecation directive in Docstrings should be placed before the extended summary #24188
Conversation
Hello @aqurilla! Thanks for submitting the PR.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, just couple of minor things
This is an extended summary with more details about | ||
what `some_old_method` does. | ||
|
||
The extended summary can contain multiple paragraphs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind of instead of this description, explain what is wrong in the PR here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have changed the description to explain what is wrong with the Docstring
scripts/validate_docstrings.py
Outdated
@@ -624,6 +625,10 @@ def get_validation_data(doc): | |||
errs.append(error('GL07', | |||
correct_sections=', '.join(correct_order))) | |||
|
|||
if (doc.deprecated and not doc.name.startswith('pandas.Panel') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there many wrong cases in Panel
? if there are just few, I'd prefer to also fix them than hardcoding this here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pandas/scripts/validate_docstrings.py
Lines 494 to 499 in 77278ba
@property | |
def deprecated(self): | |
pattern = re.compile('.. deprecated:: ') | |
return (self.name.startswith('pandas.Panel') | |
or bool(pattern.search(self.summary)) | |
or bool(pattern.search(self.extended_summary))) |
Actually Panel
has no wrong cases - I was removing it from checks due to this above existing code, which sets all Panel
related objs as deprecated.
I have changed validate_docstrings.py
now so that it checks these as well. Please have a look,
Codecov Report
@@ Coverage Diff @@
## master #24188 +/- ##
=======================================
Coverage 92.22% 92.22%
=======================================
Files 162 162
Lines 51828 51828
=======================================
Hits 47798 47798
Misses 4030 4030
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #24188 +/- ##
=======================================
Coverage 92.21% 92.21%
=======================================
Files 162 162
Lines 51723 51723
=======================================
Hits 47695 47695
Misses 4028 4028
Continue to review full report at Codecov.
|
scripts/validate_docstrings.py
Outdated
@@ -624,6 +625,12 @@ def get_validation_data(doc): | |||
errs.append(error('GL07', | |||
correct_sections=', '.join(correct_order))) | |||
|
|||
pattern = re.compile('.. deprecated:: ') | |||
if (bool(pattern.search(doc.summary)) | |||
or bool(pattern.search(doc.extended_summary))): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mind creating a property deprecated_with_directive
to avoid repeating this code?
also, not sure why we implemented it this way (and it was possibly me), but I think '.. deprecated:: ' in (doc.summary + doc.extended_summary)
is a much simpler way to do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I can do that,
I had a few doubts - did you mean to also change the current deprecated
property to use the simpler '.. deprecated:: ' in (doc.summary + doc.extended_summary)
implementation?
Also is there any special significance of the name deprecated_with_directive
? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the current deprecated
property looks for the methods/functions deprecated with the .. deprecated::
directive, and also for anything that belongs to Panel
.
So, the idea would be to have a property to check the cases deprecated with the directive (so, deprecated_with_directive
could be a sensible name for it), and then the current deprecated
property would use it, and also check for the Panel
stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks!
Have updated both properties in this manner, please have a look,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just a small detail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks @aqurilla
The failing check is due to these two methods mentioned above - |
@jreback can |
Ok, thanks! |
``numpy.ndarray`` method ``ptp``. | ||
|
||
.. deprecated:: 0.24.0 | ||
``numpy.ndarray`` method ``ptp``.\n\n.. deprecated:: 0.24.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason for doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was done so that the generated docstring matches the expected format of -
Summary
.. deprecated::
Extended Summary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the validation doesn't fail, I guess this is correct. But if you can copy the output of ./scripts/validate_docstrings.py pandas.Series.<this_method>
in a comment, so we can see how the final version is, that would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the final version, running python ./scripts/validate_docstrings.py pandas.Series.ptp --errors=GL09
gives -
################################################################################
######################## Docstring (pandas.Series.ptp) ########################
################################################################################
Returns the difference between the maximum value and the
minimum value in the object. This is the equivalent of the
``numpy.ndarray`` method ``ptp``.
.. deprecated:: 0.24.0
Use numpy.ptp instead
The unchanged generic.py
file fails the validation with an output like below, where there is additional whitespace before the deprecated directive (does not match required format) -
################################################################################
######################## Docstring (pandas.Series.ptp) ########################
################################################################################
Returns the difference between the maximum value and the
minimum value in the object. This is the equivalent of the
``numpy.ndarray`` method ``ptp``.
.. deprecated:: 0.24.0
Use numpy.ptp instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use numpy.ptp instead
should be indented with four spaces (the .. deprecated::
is not ok, aligned with the summary)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecated is correctly aligned. The rest will need to be changed (the summary should fit in a single line, and the rest should go to the standard summary), but that's from the original code, and we'll take care later in a separate PR.
So, happy with it here.
…rder Merging the changes made in 24215, to rectify the _decorators.py behavior
Also, @aqurilla if you can merge master into your branch, the PR that fixed |
50d192c
to
5599343
Compare
…tion in the docstrings (pandas-dev#24188)
…tion in the docstrings (pandas-dev#24188)
git diff upstream/master -u -- "*.py" | flake8 --diff
Two methods still show errors due to their docstrings being generated by the deprecate method in _decorators.py. I am not sure if that is to be changed.