Policy for Skimage2 docstrings
Description:
I wanted to discuss how we should go about putting on docstrings or other documentation to help users port code from Skimage1 to Skimage2.
For reference, I was prompted by this PR and comment by Lars, as well as thinking through porting in https://github.com/matthew-brett/coordinate-review/blob/main/coordinate_review.Rmd (Search for "porting" - example).
There was some more discussion on Zulip.
It seems to me we should be writing those porting docstrings now, as we work through Skimage2 changes, and think about the differences between the Skimage2 and Skimage1 API.
And we should also be thinking about some standard form for these docstrings. I evolved to something like this (another example from the document above).
This routine behaves differently in Skimage1 and Skimage2. Skimage2 specifes
the center for rotation as a coordinate in i, j (row, column) order, whereas
Skimage1 asked for the center in (column, row) order.
When porting Skimage1 code to Skimage 2, the following are equivalent:
>>> import numpy as np
>>> import skimage as ski1
>>> import skimage2 as ski2
>>>
>>> # Skimage1
>>> s_img_1 = ski1.transform.swirl(img, (10, 5))
>>> # Skimage2. Note reversal of center coordinate ordering (col, row)
>>> s_img_2 = ski2.transform.swirl(img, (5, 10))
>>> # The Skimage 1 and 2 code are equivalent.
>>> assert np.all(s_img_1 == s_img_2)What are the requirements for such docstrings? Maybe start with:
- They should be very close to the code in the source tree, so we remember to update them.
- They should not be displayed until the user is in a position to do the port. So, not before the
skimage2function exists, and perhaps not before we are confident this will be the final API for a not-experimental Skimage2 release. - When they are ready for display (and users can / should port), they should appear in the Skimage1 docstrings.
- Users of Skimage2 functions probably don't need to see these, but we might well want to reference porting notes if available. This might be something like (in the docstring): "The API of this function changed between Skimage1 and Skimage2. To see what changed, the how to port from Skimage1 to Skimage 2, do
import skimage as ski1; help(ski1.amodule.afunc)or equivalent, and maybe link to the web documentation as well.
How might that work?
How about a decorator for Skimage1 functions, that adds the porting docstring to the end of the current docstring, conditional on some flag, such as ski1._skimage2_released or similar?
Source: scikit-image/scikit-image