Skip to content

Move source to _skimage2, copy tests - #8204

Merged
stefanv merged 156 commits into
scikit-image:mainfrom
matthew-brett:ski2-megamove
Jun 12, 2026
Merged

stefanv merged 156 commits into
scikit-image:mainfrom
matthew-brett:ski2-megamove

Conversation

@matthew-brett

@matthew-brett matthew-brett commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

This is the promised megamove.

  • I moved all the code to src/_skimage2, and
  • copied all the tests from tests/skimage to tests/skimage2.
  • By hand, I restored all the code that had been overwritten in
    src/_skimage2.
  • I ran the tools/port_module.py script (now in https://github.com/scikit-image/internal-scripts/blob/b92065b/src/megamove/_port_module.py) on the src/_skimage2 tree to make shim modules in the skimage tree.
  • By hand, I restored the pre-existing shims for ported src/_skimage2
    functions in the src/skimage tree.
  • By hand, and then with Gemini and Cursor, I restored the missing _
    imports not picked up by the shims, that were using import *.
  • Mainly using Cursor and review / hand editing, I worked through the tests. In
    particular, the original skimage tests, now copied, were testing the
    skimage behavior, and in some cases, this had changed because of our pre-existing
    edits in the _skimage2 tree. The tests needed to be adapted.

Here are some thoughts that came up, as I was doing this:

  • Notice img_as_float in filters/_gaussian.py:difference_of_gaussians, as
    a temporary workaround. We should test the unscaled behavior.
  • Notice legacy-scaling hack in src/_skimage2/feature/_basic_features.py.
    Using # TODO - ski2: as comment marker for port issues that must be addressed.
  • Ditto tests/skimage2/segmentation/test_active_contour_model.py.
  • _skimage2/feature/corner.py:corner_peaks has to call peak_local_max,
    which pulls in the _skimage2 version of peak_local_max, changing default
    behavior. For the moment, adapt to that, waiting for Lars' PR to remove
    corner_peaks in _skimage2.
  • find_boundaries now pulls in the Skimage2 erosion and dilation. The
    default edge mode has changed for those functions, from mode='reflect' to
    mode='ignore'. It appears, from discussion with Cursor, that
    mode='reflect' is correct and necessary for image edges in
    find_boundaries. Added a # TODO - ski2 comment to remind us to review.
  • Note extensive changes in tests/skimage2/feature/test_peak.py to adapt to
    new peak_local_max defaults. These need review.
  • At some point, we should move rest of functions in morphology/footprints.py
    into _footprints or something else.
  • Note rename of util/look_for.py to util/_look_for.py. Module name
    previously shadowed in util namespace by function lookfor. I could find
    no code instances of /(from|import) skimage.util.lookfor/ on Github.
  • Note rename of morphology/max_tree.py to morphology/_max_tree.py. Module
    name previously shadowed in morphology namespace by function max_tree.
    I could find no code instances of /(from|import) skimage.morphology.max_tree/ on Github.
  • Note rename of morphology/_max_tree.pyx to morphology/_max_tree_cy.py.
    No code instances on Github with /(from|import) skimage.morphology._max_tree/.

Although these last renaming changes are technically API changes in skimage, given (as far as we can see) no-one appears to be using the implied API, I think it's OK to make this silent.

For an analysis of why these renames were needed, after implementing lazy loading of morphology and lookfor in the _skimage2 tree: https://github.com/matthew-brett/lazy-load-pain . In sum, with lazy loading, if one first loads a lazy-loaded namespace with from ns import *, and there is a module (say my_name) with the same name as one of the attributes, then a subsequent access of ns.my_name picks up the module not the intended attribute. I believe this was a bug in lazy-loading, fixed by scientific-python/lazy-loader#171 .

For review - it would be useful to have a look at the following commits:

  • Commit 0fb5b49 - Adapt test_gray to new morphology defaults
  • Commit cfdb195 - Adapt test_peaks to V2 behavior
  • Commit fe3080a - Move PendingDeprecationWarning to _skimage2
  • Commit 163024b - Use rescale_legacy to restore intended values
  • Commit c228708 - Enforce skimage for dispatching backends.
  • Commit 4214c63 - Adapt to changed grayscale erosion / dilation
  • Commit e7d27df - Fixes for difference_of_gaussians
  • Commit 4082428 - Fixes to allow for peak_local_max difference.
  • Commit e7cf6da - Nasty hack to get tests passing in features.
  • Commit 310f426 - Fix call of binary_blobs for ski2 conventions.
  • Commit 13366f4 - Continue Gemini changes for io / plugins
  • Commit 96005a0 - Remove references to skimage.io
  • Commit 792620b - Start of skimage2/io fix from Gemini
  • Commit f1f6448 - Refactor morphology init into init.pyi
  • Commit a896cea - Adapt lookfor to allow skimage and skimage2 search
  • Commit 4fefab3 - Adapt _public_api_names to shim namespaces in skimage.
  • Commit c4b586c - Add per-function Skimage2 warnings to future module.
  • Commit f8c022b - Refactor migration to allow classes

AI usage - I've noted this in the commit messages. For the later commits, I leaned fairly heavily on Cursor, but of course I reviewed and usually edited / renegotiated before committing.

We'll need to revert commit cea28da when this gets merged. That commit makes Pooch look for test data in the original tests/skimage tree, but after this is merged, data will be in the tests/skimage2 tree.

This change makes all pre-megamove PRs generate rather ugly merge conflicts. Cursor wrote a utility to route the changes appropriately, and specifically:

  • Test changes go both to tests/skimage2 and the original test/skimage.
  • src/skimage code changes do not go in skimage unless they are skimage wrappers for for skimage2 code. Instead they go to src/_skimage2.

I've put Cursor's scripts in a private repo for now: https://github.com/scikit-image/internal-scripts . Private because a) I haven't reviewed the code and b) I can't vouch for copyright.

Note that - after this PR - the skimage doctests will read as being _skimage2 doctests. We should adapt the shimmed functions to use skimage instead of _skimage2 for doctests. Draft Cursor implementation as follow-up PR at #8219

The code move will mess up any pickles expecting implementations to be in skimage modules. We could fix that, with the addition of some complexity. See: #8220 .

Comment thread src/skimage/conftest.py Resolved
From: scikit-image#7980 - the
filter is redundant because we're already using pytest.warns for these.
Comment thread src/skimage/_migration.py
Comment on lines +356 to +360
if inspect.isclass(func_or_class):
func_or_class.__init__ = self._wrap_callable_with_warning(
func_or_class.__init__, warn_msg, warning_cls
)
return func_or_class

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This misses initialization with classmethods which we use / may use for the transform classes.

We should probably revisit this after merging or when we get to that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, reasonable point - raise an issue so we don't forget?

lagru and others added 5 commits June 12, 2026 13:26
Comment thread src/skimage2/__init__.py Outdated
@@ -13,6 +13,8 @@
__getattr__ = _skimage2.__getattr__


# Re-use the warning category defined on ``_skimage2`` so filters and test
# harnesses can target ``ExperimentalAPIWarning`` consistently.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment. Is that an appeal to the reader to use this class? If so where? Or is that describing the following line where a warning is raised?

What is the harness in reference to? LLM-related?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to remove the comment. It was LLM-generated - I believe "harness" just means pytest + CI, and the comment was to explain why we're importing the warning rather than using a new one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

to match the warning text and porting document.
Comment thread tools/port_module.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind more (any) documentation for this script. I'm unsure what this does without having spent time reading it in detail.

Is this meant to be used in the future? If so for what? Or is this documenting an automated part of this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to remove it if you prefer. I was imagining that someone following in our footsteps might want to use it, but maybe not. I can always move it to the private scripts repository.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Comment thread src/_skimage2/util/_value_rescaling.py Resolved
from _skimage2 import filters, feature
from _skimage2.util.dtype import img_as_float32

# Ski2: address legacy scaling.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these kind of TODOs listed somewhere else?

Maybe we can update these to start with # TODO since that is commonly recognized by tooling as a TODO-item out of the box.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

matthew-brett and others added 6 commits June 12, 2026 18:18
@stefanv
stefanv enabled auto-merge (squash) June 12, 2026 21:37
@stefanv
stefanv merged commit cbab80e into scikit-image:main Jun 12, 2026
25 checks passed
@stefanv stefanv added this to the 0.27 milestone Jun 12, 2026
VihAMBR pushed a commit to VihaanAgarwal/scikit-image that referenced this pull request Jun 13, 2026
marching_cubes with a mask only consulted one corner per cube, so voxels at index 0 could never be masked and the surface could leak one cube past the mask boundary (scikit-imagegh-8202). Gate each cube on all eight corners it reads.

Rebased onto the _skimage2 source migration (scikit-image#8204); the fix and tests now live in the _skimage2 tree, with the area assertion in test_masked_marching_cubes updated in both test copies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🥾 Path to skimage2 A step towards the new "API 2.0" 🧪 run-all-tests Run all of the tests, instead of only those in subpackages that have been modified by the PR ⚠️ Priority This issue or PR should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants