Skip to content

Add links to examples from the docstrings and user guide #30621

Open
@StefanieSenger

Description

@StefanieSenger

TLDR: Meta-issue for new contributors to add links to the examples in helpful places of the rest of the docs.

Description

This meta-issue is a good place to start with your first contributions to scikit-learn.

This issue builds on top of #26927 and is introduced for easier maintainability. The goal is exactly the same as in the old issue.

Here, we improve the documentation by making the Examples more discoverable by adding links to examples in relevant sections of the documentation in the API documentation and in the User Guide:

  • the API documentation is made from the docstrings of public classes and functions which can be found in the sklearn folder of the project
  • the User Guide can be found in the doc/modules folder of the project

Together with the examples (which are in the examples folder of the project), these files get rendered into html when the documentation is build and then are displayed on the scikit-learn website.

Expectation management

Helping users find the right information among our 10.000 pages of documentation is a complex and ongoing effort. If this task was trivial or fully mapped out, we’d have finished it already. If it was solvable by using an llm-based tool, we’d have finished it already. But fact is: we need your support, your thoughtfulness and your critical thinking skills.

⚠️ Important: we expect that only about 50% of the listed examples will ultimately be linked. Your contribution includes deciding whether an example adds enough value to be referenced, and if so, where. We are aware that this is not easy, especially for new contributors. We encourage you to share your reasoning, and a team member will make the final call. Even if your example isn't linked, your evaluation is still valuable.

By working on this issue, you share responsibility with us for creating good documentation for millions of users. That means thoughtful contributions matter. Please take the time to understand the context and consider your changes carefully before opening a PR. We cannot afford to accept low-effort contributions and will close PRs that do not follow the guidelines outlined in this issue.

How long will your first PR take you up until the point you open a PR?

  • 8-16 hours if you have never contributed to a project and have only basic or no understanding of the workflow yet
  • 2-8 hours if you’re familiar with the general workflow but new to scikit-learn (closer to 2 hours if you're comfortable with linting, Sphinx, and CI)
  • 1-2 hours for your 2nd, 3rd, ... PR on the same issue for everyone
  • If it takes less time than this, your PR likely needs significant work after submission; and we want to avoid that.

How long will it take us to merge your PR?

  • we strive for a scikit-learn member to look at your PR within a week and suggest changes depending on technical quality of the PR and an assessment of added value to the user by having that additional link in the documentation
  • we strive for a maintainer to evaluate your PR within a month; they might also suggest changes before approving and merging
  • the whole process on average takes several weeks and can take up to months, depending of availability of maintainers and on how many review cycles are necessary

Workflow

We recommend this workflow for you:

  1. have pre-commit installed in your environment as in point 10 of How to contribute in the development guide (this will re-format your contribution to the standards used in scikit-learn and will spare you a lot of confusion when you are not experienced with linters)

  2. pick an example to work on

    • Make sure your example of interest had not recently been claimed by someone else by looking through the discussion of this issue (you will have to load hidden items in this discussion). Hint: If somebody has claimed an example several weeks ago and then never started it, you can take it. You can also take over tasks marked as stalled.
    • search the repo for other links to your example and check if the example is already linked in relevant parts of the docs
      • how to search the repo: a) find the file name of your example in the examples folder (it starts with plot_...); b) use full text search of your IDE to look for where that name appears
      • you can totally ignore the "Gallery examples" on the website, as it is auto-generated; do only look for real links in the repo
    • comment on the issue to claim an example (you don't need to wait for a team member's approval before starting to work)
    • in this issue, no tasks gets assigned; instead you are responsible to make sure the task you want to work on is available
  3. find suitable spots in either the API documentation or the User Guide (or both) where users would be happy to find your example linked, or if this example doesn't need new references

    • read through your example and understand where it is making its most useful statements
    • many examples are already sufficiently linked, please comment on this issue if you find your example already sufficiently linked; this kind of contribution is highly appreciated
    • how to know where a link is most useful
      • if the example demonstrates a certain real world use case: find where in the User Guide the same use case is treated or could be treated
      • if the example shows how to use a certain param: the param description in the API documentation might be a good spot to put the link
      • if the example compares different techniques: this highly calls for mentioning it in the more theoretical parts of the User Guide
      • ideally, you integrate the link into the text and if you add a link like this :ref:`title <link>`, you can change its title so that the example's title gets substituted by your picked title and the link can be fitted more nicely to the sentences
    • where not to put links:
      • do not put links into the .. rubric:: See Also section, which we aim to reserve for links to other API functionalities, not examples
      • do not put links into the .. rubric:: Examples section in a classes docstring, which we aim to reserve for code snippets only
      • do not put a new link directly before or after another linked example, since we aim to add the links in the most relevant places
      • do not add a new .. rubric:: Examples section anywhere
  4. add links

    • An example with the path examples/developing_estimators/sklearn_is_fitted.py would be referenced like this:
      :ref:`sphx_glr_auto_examples_developing_estimators_sklearn_is_fitted.py`
    
  5. test build the documentation before opening your PR

  6. open PR

    • use a PR title like DOC add links to <name of example> (starting with DOC)
    • do not refer to this issue on the title of the PR, instead:
    • do refer to this issue using in the Reference Issues/PRs section of your PR, do refer to this issue using "Towards #30621" (do not use "Closes #..." or "Fixes #...")
  7. check the CI

    • After the CI tests have finished (~90 minutes) check if all the tests have passed.
    • If the CI shows any failure, you should to take action by investigating and pushing a new commit with a fix; as a rule of thump, you can find the most useful information from the CIs, if you click the highest links marked in red first (these are the failures); in any case you need to click through several layers until you see actual test results with more information (and until it looks similar to running pytest, ruff or doctest locally). If you have never done this before, it is likely that you have to spend a few hours to google to find out why your tests fail.
    • In the CI, you can find one that says "Check the rendered docs here!". In there, you can look into how the CI has built the documentation for the changed files to check if everything looks alright. You will see something like auto_examples/path_to_example, [dev], [stable], where the first link is your branche's version, the second is the main dev branch and the third link is the last released scikit-learn version that is used for the stable documentation on the website.
    • If the CI shows linting issues, check if you have installed and activated pre-commit properly, and fix the issue by the action the CI proposes (for instance adding or deleting an empty line)
    • If you are lost and don't know what to do with a CI failure, look through other PRs from this issue; most things have already happened to others.
    • Sometimes, http request errors such as 404 or 405 show up in the CI, in which case you should push an empty commit (git commit --allow-empty -m "empty commit to re-trigger CI") to re-trigger the CI. In the next run, usually the http request errors don't happen again.
  8. wait for reviews and be ready to adjust your contribution later on

ToDo

Here's a list of all the remaining examples:

What's next?

Note for AI/LLM-based tools and their users

This issue requires human judgment, contextual understanding, and familiarity with scikit-learn’s documentation structure and goals. It is not suitable for automatic processing by AI tools or casual use of code assistants.

Please do not generate PRs with the help of AI tools unless you have deeply reviewed the example and the surrounding documentation, carefully assessed relevance and added value, and can explain your reasoning clearly. Shallow or semi-automated PRs without proper evaluation will not be accepted and create unnecessary work for maintainers.

Please direct users to engage with the task manually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationMeta-issueGeneral issue associated to an identified list of tasksSprintgood first issueEasy with clear instructions to resolve

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions