-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
The data decorator does not integrate well with numpydoc #10189
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
Comments
I vote for the PS option (format a custom data entry). |
The decorator used to add a Putting the information in Parameters or Other Parameters is best, not sure the right way to do that though. Putting in a templatting string in works but requires coordination between two places (the decorator and the docstring). Having the decorator parse the docstring as numpydoc, insert the lines and then write it back out is also an option, but I am not sure what the start-up time cost of that is. We already have some pretty significant docstring templating going on (and discussions about removing it) so I am not sure that the net run-time cost will be that large. Another option is a helper that just re-writes the source to extend the docstring, but that is probably the worst of all worlds. |
Why not?
That's true, but the decorator can easily check if it could modify the docstring using formatting and warn otherwise. |
Until this is resolved, I will use an empty Notes section with a standard comment.
This will make a possible later migration easier. |
Looks like this will be fixed by #14029 |
Fixed by #14029. |
Bug report
Bug summary
From a discussion in #10186: The data note inserted in the docstring via
@_preprocess_data
can be displayed in unexpected places in the generated html documentation.Examples
Reason
I'm not an expert in numpydoc, but from my understanding, this is the issue:
@_preprocess_data
just appends an admonition@_preprocess_data
does not add a section, the admonition belongs to whatever section was last. For sections that are plain top-level such as Notes or Examples, this looks ok (though technically the note is part of the example). It goes wrong for differently formatted or reordered sections (e.g. indented Other Parameters or contained in a See Also box). Example docstring:Solution
To do this correctly, the inserted admonition should always be part of a Notes section. There are diffent ways to achieve this:
@_preprocess_data
do always end with a Notes section. Manually add an empty one if there is none.@_preprocess_data
add the Notes section. This is not trivial because you may or may not have an Notes section already and duplicated sections are not allowed (ENH: merge duplicate sections (rather than raise) numpy/numpydoc#67 could help on this).@_preprocess_data
to not append someting, but format. Advantage: This is more explicit and prevents surprises. Disadavantage: The documenter has to know that the note has to be added and do it manually (But at least@_preprocess_data
could warn if it could not format its note into the docstring). The docstring could look like this:There may be other options like extending numpydoc to have an additional custom Data Note section, but I don't think its worth the effort.
For now, I use option 1. as a simple workaround on a case by case basis (also in #10186).
2. would be too much magic.
In the long run, I propose to switch to option 3.
PS
Just got another idea possibly worth considering. If we change to formatting anyway, one could get rid of the admonition and format a custom data entry into the Paramters or Additonal Paramters section:
The text was updated successfully, but these errors were encountered: