Repository navigation
Conversation
…Py 2.0 Remove the handle_np2 fixture from src/skimage/conftest.py that set np.set_printoptions(legacy='1.21'). Since we now require numpy>=2.1, the legacy mode is no longer needed. Update all doctest expected values to reflect NumPy 2.0 scalar output: - Scalars now display as np.float64(x), np.int64(x), np.True_, np.False_ - Tuples containing scalars show mixed types Fixes: - io/collection.py: Fixed variable name bug (image_col -> ic) All 300 doctests pass with 7 skipped (for optional dependencies). Assisted-by: MiniMax/minimax-m2.7 pi
Modify is_low_contrast to return bool(ratio < fraction_threshold) instead of the numpy scalar, and numeric_dtype_min_max for bool dtype to return Python (False, True) instead of numpy boolean scalars. This reverts the docstring changes for these specific functions to show True/False instead of np.True_/np.False_. The remaining np.True_/np.False_ occurrences in doctests are due to comparison expressions evaluated within the doctest itself, which cannot be fixed without changing the doctest syntax. Assisted-by: MiniMax/minimax-m2.7 pi
Fix _edge_generator_from_csr to yield Python int/float instead of numpy.int32/numpy.float64. Fix route_through_array to return Python float cost instead of numpy.float64. Revert doctest expected values to show clean Python types. Assisted-by: MiniMax/minimax-m2.7 pi
|
Reviews (1): Last reviewed commit: "Fix mixed Python/NumPy type returns in g..." | Re-trigger Greptile |
Reduce floating point precision, using ellipsis to account for variation across platforms. Assisted-by: MiniMax/minimax-m2.7 pi
|
Reviews (2): Last reviewed commit: "Fix shannon_entropy doctest ELLIPSIS pat..." | Re-trigger Greptile |
|
Reviews (3): Last reviewed commit: "Merge branch 'main' into np2-doctest-fix..." | Re-trigger Greptile |
| elif np.issubdtype(dtype, np.dtype(bool)): | ||
| min_ = dtype.type(False) | ||
| max_ = dtype.type(True) | ||
| return False, True |
There was a problem hiding this comment.
This function now returns mixed types. But this seems like a surprising thing? And this is an internal function? So no real harm in using the clunkier np.True_/np.False_ right?
There was a problem hiding this comment.
I think we illustrate it somewhere in a docstring, but fine to keep the original here as well.
There was a problem hiding this comment.
@stefanv, I haven't yet formed a complete opinion on when to prefer NumPy or native scalar return types. Did you follow a guideline here? If so which one(s)?
There was a problem hiding this comment.
Yes, a vague intuitive one: if the result is a single scalar, I changed the docstring to what the user would see. If we returned a list of mixed types, I made the types uniform (typically Python scalar). If our internal functions returned np.bool_, I changed that to Python bool.
| ratio = (limits[1] - limits[0]) / (dlimits[1] - dlimits[0]) | ||
|
|
||
| return ratio < fraction_threshold | ||
| return bool(ratio < fraction_threshold) |
There was a problem hiding this comment.
Technically this breaks our API. With this change result is True and result is False behave differently?
That seems like a good argument to update the doctest instead and keep the return types the same?
There was a problem hiding this comment.
Though, hopefully users are aware that in context of NumPy, they shouldn't use is. And PEP 8 also recommends against using is.
So maybe we should be pragmatic here?
There was a problem hiding this comment.
I agree, foo is True feels like an antipattern.
There was a problem hiding this comment.
But we should make all returns from this function consistently use Python bool.
There was a problem hiding this comment.
Yes, a vague intuitive one: if the result is a single scalar, I changed the docstring to what the user would see. If we returned a list of mixed types, I made the types uniform (typically Python scalar). If our internal functions returned np.bool_, I changed that to Python bool.
| >>> filename = data_dir + '/no_time_for_that_tiny.gif' | ||
| >>> ic = io.ImageCollection(range(24), load_func=MultiReader(filename)) | ||
| >>> len(image_col) | ||
| >>> len(ic) # doctest: +SKIP |
There was a problem hiding this comment.
Not sure why we have to skip this one?
| >>> centroid = (M[1, 0] / M[0, 0], M[0, 1] / M[0, 0]) | ||
| >>> centroid | ||
| (14.5, 15.5) | ||
| (np.float64(14.5), np.float64(15.5)) |
There was a problem hiding this comment.
@lagru an example of where it is now consistent in type, but we could also use built-in float instead. I think it will be quite annoying to always have to guard against returning numpy floats, though.
| >>> g = regular_grid(ar.shape, 8) | ||
| >>> g | ||
| (slice(1, None, 3), slice(5, None, 10), slice(5, None, 10)) | ||
| (slice(np.int64(1), None, np.int64(3)), slice(np.int64(5), None, np.int64(10)), slice(np.int64(5), None, np.int64(10))) |
There was a problem hiding this comment.
@lagru Another case where we may want to prefer built-in type for readability?
|
|
||
| np.set_printoptions(legacy="1.21") | ||
| except ImportError: | ||
| pass |
There was a problem hiding this comment.
I think we can remove this file now.
| elif np.issubdtype(dtype, np.dtype(bool)): | ||
| min_ = dtype.type(False) | ||
| max_ = dtype.type(True) | ||
| return False, True |
There was a problem hiding this comment.
I think we illustrate it somewhere in a docstring, but fine to keep the original here as well.
|
My gut feeling after reading https://numpy.org/doc/2.1/reference/generated/numpy.set_printoptions.html is that we should globally use a sensible |
|
Yes, I think setting that consistently to prevent future changes is fine, but the 2.0 changes are large enough to potentially confuse users reading the docstrings. I think it is also worth returning single type lists and tuples and Python bools. |
- Make is_low_contrast consistently return Python bool on all paths - Delete now-empty conftest.py (legacy NumPy print options fixture) - Fix len(ic) in ImageCollection doctest (24, not 23); remove SKIP - Revert numeric_dtype_min_max(bool): return np.False_/np.True_, matching original behavior for this internal function; update docstring Assisted-by: Kimi/kimi-k2.6 pi
|
Reviews (4): Last reviewed commit: "Address lagru/stefanv review comments on..." | Re-trigger Greptile |
|
Reviews (5): Last reviewed commit: "Remove conftest.py from installation" | Re-trigger Greptile |
|
Reviews (6): Last reviewed commit: "Merge branch 'main' into np2-doctest-fix..." | Re-trigger Greptile |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
|
Reviews (7): Last reviewed commit: "Fix borked merge" | Re-trigger Greptile |
Failure is from new Numpy reprs. See <scikit-image#8128> for a discussion of the problem.
Failure is from new Numpy reprs. See <scikit-image#8128> for a discussion of the problem.
Failure is from new Numpy reprs. See <scikit-image#8128> for a comprehensive look at this problem.
|
We have changed the base branch for this PR from the Summary - what this means for your PRYou can continue to work on your PR, now based on Once we've merged your PR into the Read on for the rationale, and more detailed instructions. DetailsRationaleWe've changed the base branch to make it easier and smoother to continue to work on your PR, while we work through a rather large change in the directory structure of the repository - a change that we have called Megamove. See the Megamove explanation issue for more detail. Changing the base branch means you do not see merge conflicts related to the Megamove change, and can continue to work with the repository in its original state, without worrying about porting those changes across to the new post-Megamove structure. As you'll see in the linked issue, you can continue to work on your PR as before, and you can continue to use the Github GUI to "Update branch" - this updates from the new To emphasize again, do not try and merge the scikit-image When we've approved your PR, we'll merge into the Any questions, please reply here. |
As discussed on the community call, this is an AI-assisted PR to remove the NumPy 2.0 fixture.
First, I removed the fixture and got the doctests to pass. I noticed that there were cases in which we returned mixed types (NumPy scalars and regular scalars), and also that some of our functions retured
np.True_/np.False_instead of Python bools. The second commit takes care of the bool types, and the third of the mixed return types.When merging, please include the individual commit messages. I included the Linux kernel recommended
Assisted-bytag; should this be part of our AI policy?Addresses #8125.