Skip to content

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

Merged
merged 7 commits into from
Dec 16, 2018

Conversation

aqurilla
Copy link
Contributor

@aqurilla aqurilla commented Dec 9, 2018

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.

@pep8speaks
Copy link

Hello @aqurilla! Thanks for submitting the PR.

Copy link
Member

@datapythonista datapythonista left a 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.
Copy link
Member

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.

Copy link
Contributor Author

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

@@ -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')
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link

codecov bot commented Dec 10, 2018

Codecov Report

Merging #24188 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24188   +/-   ##
=======================================
  Coverage   92.22%   92.22%           
=======================================
  Files         162      162           
  Lines       51828    51828           
=======================================
  Hits        47798    47798           
  Misses       4030     4030
Flag Coverage Δ
#multiple 90.62% <ø> (ø) ⬆️
#single 43% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/multi.py 95.58% <ø> (ø) ⬆️
pandas/core/generic.py 96.65% <ø> (ø) ⬆️
pandas/core/indexes/base.py 96.27% <ø> (ø) ⬆️
pandas/core/series.py 93.7% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 040f06f...5599343. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 10, 2018

Codecov Report

Merging #24188 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24188   +/-   ##
=======================================
  Coverage   92.21%   92.21%           
=======================================
  Files         162      162           
  Lines       51723    51723           
=======================================
  Hits        47695    47695           
  Misses       4028     4028
Flag Coverage Δ
#multiple 90.61% <ø> (ø) ⬆️
#single 43.03% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/multi.py 95.58% <ø> (ø) ⬆️
pandas/core/generic.py 96.65% <ø> (ø) ⬆️
pandas/core/indexes/base.py 96.27% <ø> (ø) ⬆️
pandas/core/series.py 93.7% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77278ba...3950b3c. Read the comment docs.

@@ -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))):
Copy link
Member

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

Copy link
Contributor Author

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!

Copy link
Member

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.

Copy link
Contributor Author

@aqurilla aqurilla Dec 10, 2018

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,

Copy link
Member

@datapythonista datapythonista left a 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

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks @aqurilla

@aqurilla
Copy link
Contributor Author

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.

The failing check is due to these two methods mentioned above - pandas.Series.argmax and pandas.Series.argmin whose docstrings are generated by _decorators.py. What would be the best way to resolve these?

@datapythonista
Copy link
Member

@jreback can Series.argmin and Series.argmax, deprecated in 0.21.0 be removed for 0.24.0? Or arent' we removing deprecated stuff until 1.0?

@datapythonista
Copy link
Member

@aqurilla I created #24215 which will fix the errors caused by argmin and argmax. Once it's merged, if you merge master into your branch, it should pass the CI.

@datapythonista datapythonista self-assigned this Dec 11, 2018
@aqurilla
Copy link
Contributor Author

Ok, thanks!

``numpy.ndarray`` method ``ptp``.

.. deprecated:: 0.24.0
``numpy.ndarray`` method ``ptp``.\n\n.. deprecated:: 0.24.0
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

@aqurilla aqurilla Dec 14, 2018

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

Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually displays like below, I think when I pasted the text here it got reformatted -

image

Is this ok?

Copy link
Member

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
@datapythonista
Copy link
Member

Also, @aqurilla if you can merge master into your branch, the PR that fixed argmin and argmax has been merged, and the CI should be green now.

@aqurilla aqurilla force-pushed the fix_deprecation_order branch from 50d192c to 5599343 Compare December 14, 2018 16:36
@datapythonista datapythonista merged commit d9c814f into pandas-dev:master Dec 16, 2018
@datapythonista
Copy link
Member

Thanks for the fixes @aqurilla

@WillAyd, feel free to open a PR to merge the deprecate methods you mentioned. I think that'll make easier to understand what you meant, than discussing in comments.

Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Deprecation directive in docstrings should be placed before the extended summary
4 participants