Docs: make all API reference examples self-contained
@sadielbartholomew is already working on this.
Since Apr 17, 2020.
- Dominant language
- Python
- Stars
- 150
- Forks
- 23
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 2
Description
Some code examples for functions & methods (etc.) in the API reference of the documentation start from a pre-defined state where required fields have already been setup by unspecified code, e.g. (from here) the cf.Bounds.has_property example begins with an undefined f of nature irrelevant:
>>> f.set_property('project', 'CMIP7')
>>> f.has_property('project')
True
whereas the remainder are 'sefl-contained' in that they can be executed directly without error in Python, assuming only an appropriate environment & having run import cf, e.g (from here) where d is defined before it is used for illustration:
>>> d = cf.Data([[4, 2, 1], [1, 2, 3]], 'metre')
>>> d.unique()
<CF Data: [1, 2, 3, 4] metre>
We should convert those in the former state to the latter state by specifying required setup steps. Not only would it make it more useful to users so they can explore the examples more readily, it is a prerequisite to adding docstring example checking (see #57).
Preferably, fields etc. of the required nature would be created using cf construction methods, to promote those. Failing that, they can be created &/or adapted form one of the cf.example_field field constructs, & as part of this work it may be useful to extend the number of those for variety to minimise such example setup.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.