Skip to content

DOC: Fix malformed docstrings in ma. - #16296

Merged
mattip merged 6 commits into
numpy:masterfrom
takanori-pskq:wb7
Jun 11, 2020
Merged

mattip merged 6 commits into
numpy:masterfrom
takanori-pskq:wb7

Conversation

@takanori-pskq

Copy link
Copy Markdown

Fixing documents for some functions in numpy.ma(e.g. numpy.ma.vstack, https://numpy.org/devdocs/reference/generated/numpy.ma.vstack.html ). The documents is malformed because the indent of notes section is wrong.

Comment thread numpy/ma/extras.py Outdated
Comment on lines 261 to 263
locdoc = "\n\n Notes\n -----\n "\
"The function is applied to both the _data"\
" and the _mask, if any."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps instead we should use inspect.cleandoc(doc) before concatenating?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@eric-wieser Thanks for reviewing. I think that's right, so I fixed the code.

@charris charris changed the title DOC: fixing malformed documents DOC: Fix malformed docstrings in ma. May 19, 2020

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Applying cleandoc is definitely an improvement. Just had a quick thought on the linebreaking in locdoc.

Comment thread numpy/ma/extras.py Resolved
@takanori-pskq

Copy link
Copy Markdown
Author

I found a function ma.doc_note which solves the wrong indent problem, and the problem mentioned in the docstring of getdoc:

   .. warning::
     If the function docstring already contained a Notes section, the
     new docstring will have two Notes sections instead of appending a note
     to the existing section.

So I think it's better to use ma.doc_note.

@eric-wieser

Copy link
Copy Markdown
Member

Unfortunately ma.doc_note is also broken (#16309), but you're right that using it here is sensible.
Someone can fix doc_note in a later PR.

@eric-wieser

Copy link
Copy Markdown
Member

Proof that this seems to be working as intended: https://13466-908607-gh.circle-artifacts.com/0/doc/build/html/reference/generated/numpy.ma.vstack.html

@mattip

mattip commented May 20, 2020

Copy link
Copy Markdown
Member

Close/Reopen to clear CI failure

@takanori-pskq

Copy link
Copy Markdown
Author

Now doc_note was fixed (#16311), so this change also works correctly.

Comment thread numpy/ma/extras.py Resolved
Co-authored-by: Eric Wieser <[email protected]>
Comment thread numpy/ma/extras.py
locdoc = "Notes\n-----\nThe function is applied to both the _data"\
" and the _mask, if any."
return '\n'.join((sig, doc, locdoc))
doc = ma.doc_note(doc, "The function is applied to both the _data "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if as a follow-up we can set self.__wrapped__ = npfunc to avoid having to add a manual signature line.

@mattip
mattip merged commit 02d66ec into numpy:master Jun 11, 2020
@mattip

mattip commented Jun 11, 2020

Copy link
Copy Markdown
Member

Thanks @takanori-pskq

@takanori-pskq
takanori-pskq deleted the wb7 branch June 11, 2020 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants