Skip to content
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

Adding (DEPRECATED) prefix to deprecated objects summary in the documentation #19220

Merged
merged 1 commit into from
Apr 14, 2018
Merged

Adding (DEPRECATED) prefix to deprecated objects summary in the documentation #19220

merged 1 commit into from
Apr 14, 2018

Conversation

datapythonista
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

In #18934, @jorisvandenbossche pointed out that replacing a "manual" DEPRECATED comment at the beginning of the docstrings by the .. deprecated:: sphinx directive had a drawback: in the summary pages of the documentation, it doesn't show that the method is deprecated anymore.

This PR shows a way (there are surely others) of using the sphinx directive to add the DEPRECATED prefix automatically.

So, for example, in a page like https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html, in the list of methods, if abs was deprecated, instead of the current text (in the right column):

Return an object with absolute value taken–only applicable to objects that are all numeric.

if would show:

(DEPRECATED) Return an object with absolute value taken–only applicable to objects that are all numeric.

Personally I think this way is cleaner than adding the DEPRECATED text to each docstring.

@datapythonista
Copy link
Member Author

I think it wasn't clear in the description. This PR isn't finished and shouldn't be committed, it's just to show the general idea on what could be done. I'll finish if after some discussion this seems like a good approach.

@jreback jreback added the Docs label Jan 13, 2018
@jreback
Copy link
Contributor

jreback commented Jan 13, 2018

can you post a screen shot of the new version? (just a sample where we have actual deprecated showing)

@datapythonista
Copy link
Member Author

Sure @jreback , here you have:

screenshot_deprecated

The change in this pull request only affects these autosummaries. For the detail page, with the directive it's already shown. But may be we can customize the sphinx template and make it more visible:

deprecated_detail

@jreback
Copy link
Contributor

jreback commented Jan 13, 2018

on the auto summaries is it possible to just have: [(DEPRECATED) what the function does?]
(e.g. not have the double deprecation thng)

@datapythonista
Copy link
Member Author

Oh, didn't see it. Yes, the idea is what you say, if you check the Series.sortlevel method in the same screenshot, you'll see it. I'll check what's wrong with argmin and argmax, I guess they don't have a description for being deprecated with the deprecate function.

Does it look like a good idea then? It was a proof of concept, as @jorisvandenbossche thought that adding the DEPRECATED word manually could be simpler. If this approach sounds good, I'll finish and fix the PR (it's showing the DEPRECATED word when a parameter is deprecated but not the function/method).

@jreback
Copy link
Contributor

jreback commented Jan 13, 2018

@datapythonista ok, so it was just an issue with that doc-string. that's ok then.

I think if we can (and you show its straightforward) to do this autmatically then that is the best. manually doing things is always error prone. Sure we have to add the deprecated directive, but at least its only one thing we are adding.

@jorisvandenbossche
Copy link
Member

Didn't look in detail yet, but a simple '.. deprecated::' in obj.__doc__ won't be enough as this also detects deprecated parameters (although that should be fixable with some extra complexity)

I agree this does look like a nice and rather simple method to fix the autosummary tables (although I personally still think the more 'screaming' DEPRECATED can also be useful for plain text docstrings to users don't miss it, but I won't press on that)

@jorisvandenbossche
Copy link
Member

Didn't look in detail yet, but a simple '.. deprecated::' in obj.doc won't be enough as this also detects deprecated parameters (although that should be fixable with some extra complexity)

Ah, I didn't read your last comment in detail as you already mentioned that yourself!

@datapythonista
Copy link
Member Author

Yep, I was aware @jorisvandenbossche.

I just pushed a version that does the right thing (just add the deprecation string if the method is deprecated, not the parameters).

I reviewed argmin and argmax, and as I guessed, they don't have a docstring because they use the deprecate decorator (which includes the deprecated directive to identify the methods from the docstring). So, the result is that the directive is taken as the summary in the autosummary.

Please let me know if the PR looks all right now.

Thanks!

@staticmethod
def _is_deprecated(real_name):
from sphinx.ext.autosummary import _import_by_name
from numpydoc.docscrape import NumpyDocString
Copy link
Contributor

Choose a reason for hiding this comment

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

can these imports go at the top?

@datapythonista
Copy link
Member Author

@jreback, the numpydoc import can't be at the very top, because it requires the sphinxext directory to be in the PYTHONPATH. I moved it after the update of sys.path.

@jreback jreback added this to the 0.23.0 milestone Jan 21, 2018
@jreback
Copy link
Contributor

jreback commented Jan 21, 2018

@TomAugspurger @jorisvandenbossche ok with this?

@jreback
Copy link
Contributor

jreback commented Feb 26, 2018

@jreback
Copy link
Contributor

jreback commented Apr 1, 2018

can you rebase

happy to merge this

@datapythonista
Copy link
Member Author

Rebased, thanks!

@jreback jreback merged commit 2acce77 into pandas-dev:master Apr 14, 2018
@jreback
Copy link
Contributor

jreback commented Apr 14, 2018

thanks @datapythonista have a look at the built docs to verify this looks ok

@datapythonista
Copy link
Member Author

Thanks! Looking good:

pandas_deprecated

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.

3 participants