Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DOC Improve Contributer guide for writting docstrings #31330

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 4 commits into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion 23 doc/developers/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,19 @@ We are glad to accept any sort of documentation:

.. dropdown:: Guidelines for writing docstrings

* You can use `pytest` to test docstrings, e.g. assuming the
`RandomForestClassifier` docstring has been modified, the following command
would test its docstring compliance:

.. prompt:: bash

pytest --doctest-modules sklearn/ensemble/_forest.py -k RandomForestClassifier
glemaitre marked this conversation as resolved.
Show resolved Hide resolved

* The correct order of sections is: Parameters, Returns, See Also, Notes, Examples.
See the `numpydoc documentation
<https://numpydoc.readthedocs.io/en/latest/format.html#sections>`_ for
information on other possible sections.

* When documenting the parameters and attributes, here is a list of some
well-formatted examples

Expand Down Expand Up @@ -791,7 +804,15 @@ We are glad to accept any sort of documentation:
SelectKBest : Select features based on the k highest scores.
SelectFpr : Select features based on a false positive rate test.

* Add one or two snippets of code in "Example" section to show how it can be used.
* The "Notes" section is optional. It is meant to provide information on
specific behavior of a function/class/classmethod/method.

* A `Note` can also be added to an attribute, but in that case it requires
using the `.. rubric:: Note` directive.

* Add one or two **snippets** of code in "Example" section to show how it can
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should add that the code should be runable as is - i.e. should include all required imports?

be used. The code should be runable as is, i.e. it should include all
required imports. Keep this section as brief as possible.


.. dropdown:: Guidelines for writing the user guide and other reStructuredText documents
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.