You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Link API docs to user guide and other examples #5816
Our API docs are generated by the function docstrings, and these are usually the first thing users hit when they search for functions. However, these docstring uniformly lack examples, often leaving users stuck.
I see two ways to mitigate this:
Add examples directly to the docstings (suggested by @jklymak)
Cross reference other examples from the user guide or other tutorials
I agree, this is would be really helpful. There's lots to do, though: a small script reports about 170 functions / methods without example sections (and 6 numpy wrappers), and all others could use reviews:
For some of those it might be difficult to write examples for (i.e. the I/O methods / functions), and modifying the docstring of the numpy wrappers would require some refactoring.
Most of the remaining ones are pretty easy to figure out and write examples for, however. If we remove the entry barrier as much as possible maybe these can be good first PRs with high impact?
I'm not really sure how to do that, though... I'd try to group them by difficulty and create sub-issues with a check list for each group (so they're easy to find), and maybe also explain what a good example looks like or link to a appropriate explanation. The latter might be a good thing to add to the contributor's guide, too.
Hi, I'd like to contribute docstring examples, starting with a single API to keep the PR small. Is there a particular API you'd like prioritized, and has #6793 already covered any of the APIs in scope?
Activity
jklymak commentedon Sep 24, 2021
I think doing both is always appreciated: short "how to" with a common pattern or two and then a "see also".
raybellwaves commentedon Sep 24, 2021
See https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L2022
for how to link the doc string to other parts of the docs
keewis commentedon Oct 10, 2021
I agree, this is would be really helpful. There's lots to do, though: a small script reports about 170 functions / methods without example sections (and 6 numpy wrappers), and all others could use reviews:
analysis script
analysis report in current main (with coarse filtering of advanced / deprecated API)
For some of those it might be difficult to write examples for (i.e. the I/O methods / functions), and modifying the docstring of the numpy wrappers would require some refactoring.
Most of the remaining ones are pretty easy to figure out and write examples for, however. If we remove the entry barrier as much as possible maybe these can be good first PRs with high impact?
I'm not really sure how to do that, though... I'd try to group them by difficulty and create sub-issues with a check list for each group (so they're easy to find), and maybe also explain what a good example looks like or link to a appropriate explanation. The latter might be a good thing to add to the contributor's guide, too.
zheng-guannan577 commentedon Nov 9, 2026
Hi, I'd like to contribute docstring examples, starting with a single API to keep the PR small. Is there a particular API you'd like prioritized, and has #6793 already covered any of the APIs in scope?