Skip to content

Add skimage2 version of binary_blobs with updated signature - #7976

Merged
lagru merged 41 commits into
scikit-image:mainfrom
lagru:sk2-binary-blobs
Jan 30, 2026
Merged

lagru merged 41 commits into
scikit-image:mainfrom
lagru:sk2-binary-blobs

Conversation

@lagru

@lagru lagru commented Dec 2, 2025 •

Copy link
Copy Markdown
Member

Description

Closes #7945. This replaces the old length and n_dim arguments with a single shape argument. This allows generating images with varying dimension lengths.

  • Still need to document this in the migration guide.
  • And this also needs appropriate warnings that we can eventually make visible.

Checklist

Release note

For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.

Add `skimage2.data.binary_blobs` with improved signature compared to the old
version in `skimage.data`. The old version is now a simple wrapper around the
implementation in `skimage2`.
Add `skimage._shared._warnings.warn_external` which automatically sets the correct
stacklevel for warnings.

This replaces the old `length` and `n_dim` arguments with a single
`shape` argument. This allows generating images with varying dimension
lengths.
@lagru lagru added ⏩ type: Enhancement Improve existing features 🥾 Path to skimage2 A step towards the new "API 2.0" labels Dec 2, 2025
Comment thread src/skimage2/data/_synthetic.py Resolved
lagru added 2 commits December 8, 2025 21:36
This avoids problems due to different stack depths between the skimage
and skimage2 API. We'd have to set a different `stacklevel` depending
for skimage2 and skimage.
Comment thread LICENSE.txt Resolved
Comment thread src/skimage/_shared/_warnings.py Resolved
@lagru
lagru marked this pull request as ready for review December 8, 2025 20:41
Co-authored-by: Stefan van der Walt <[email protected]>
Comment thread src/skimage2/data/_synthetic.py Resolved
The previous regex would never match because the "__name__" might not
be just "skimage" or "skimage2". The new regex also matches
"skimage.something".
Might avoid a potentially endless loop if there's an error in the
breaking logic of the loop
lagru added a commit that referenced this pull request Dec 31, 2025
I think in practice this file is changed far to often for unrelated
reasons. Thus resulting in a significant waste of resources (for example
#7889 or
#7976). We are
periodically building and testing wheels for our nightlies. So we should
still catch stuff early. And if necessary there's always the option to
use a `maintenance/*` branch.

@stefanv stefanv left a comment

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 the blob_size_fraction argument; otherwise all seems well to me. Some minor tweaks required to LICENSE files.

Comment thread src/skimage/_shared/_warnings.py Resolved
Comment thread src/skimage/data/_binary_blobs.py Resolved
Comment thread src/skimage/data/_binary_blobs.py Resolved
Comment thread src/skimage2/data/_synthetic.py Resolved
Comment thread src/skimage2/data/_synthetic.py Resolved
Comment thread src/skimage2/data/_synthetic.py Resolved
Comment thread tests/skimage2/data/test_synthetic.py Resolved
Comment thread LICENSE.txt Resolved
Comment thread LICENSE.txt Resolved
Comment thread TODO.txt Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/skimage2/data/_synthetic.py`:
- Around line 108-109: Validate the volume_fraction argument before calling
np.quantile: check that volume_fraction is a numeric scalar and 0 <=
volume_fraction <= 1, and if not raise a ValueError with a clear message
referencing the parameter (e.g. "volume_fraction must be between 0 and 1, got
{value}"). Add this check immediately before the lines computing threshold =
np.quantile(mask, 1 - volume_fraction) / blobs = mask >= threshold so
out-of-range inputs produce a user-friendly error.

Comment thread src/skimage2/data/_synthetic.py Resolved
@coderabbitai coderabbitai Bot added the 📜 type: API Involves API change(s) label Jan 29, 2026
@lagru lagru removed the 📜 type: API Involves API change(s) label Jan 29, 2026

@mkcor mkcor left a comment

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.

Thanks for iterating with me, @lagru!

So ski2 it is, perfect!

Thanks for clarifying what the 'API boundary' meant; I get it now. I'm not familiar with the term 'frame' in this context though: Isn't it 'block' as in 'code block?' Or 'code unit?'

I left only minor (wording) suggestions, so I'll go ahead and commit them.

Comment thread src/skimage/data/_binary_blobs.py Resolved
Comment thread src/skimage/_shared/_warnings.py Resolved
Comment thread src/skimage/_shared/_warnings.py Resolved
Comment thread src/skimage2/data/_synthetic.py Resolved
Comment thread tests/skimage2/data/test_synthetic.py Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/skimage/_shared/_warnings.py (1)

160-166: Consider documenting category as optional with its default value.

The numpydoc format typically includes "optional" and the default value for keyword arguments with defaults.

✍️ Proposed docstring update
     Parameters
     ----------
     message : str
         Warning message.
-    category : type[Warning]
+    category : type[Warning], optional
         The class used in the warning.
+        Default is ``None``, which emits a ``UserWarning``.
     """

As per coding guidelines, all code should be documented using the NumPy/SciPy docstring standard (numpydoc format).

Comment thread src/skimage2/data/_synthetic.py Resolved

@mkcor mkcor left a comment

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.

If CI is green and I don't hear anything, I'll merge in ~6 hours, because it's currently holding #7858 back. @lagru feel free to merge earlier if you see fit.

Comment thread src/skimage/_shared/_warnings.py Resolved
Comment thread src/skimage/data/_binary_blobs.py Resolved
Comment thread src/skimage2/data/meson.build Resolved
@lagru
lagru merged commit 02693c8 into scikit-image:main Jan 30, 2026
@stefanv stefanv added this to the 0.27 milestone Jan 30, 2026
@lagru
lagru deleted the sk2-binary-blobs branch January 30, 2026 13:54
FelipeCybis pushed a commit to FelipeCybis/scikit-image that referenced this pull request Jun 9, 2026
…kit-image#7995)

I think in practice this file is changed far to often for unrelated
reasons. Thus resulting in a significant waste of resources (for example
scikit-image#7889 or
scikit-image#7976). We are
periodically building and testing wheels for our nightlies. So we should
still catch stuff early. And if necessary there's always the option to
use a `maintenance/*` branch.
FelipeCybis pushed a commit to FelipeCybis/scikit-image that referenced this pull request Jun 9, 2026
…mage#7976)

Closes scikit-image#7945. 

Add `skimage2.data.binary_blobs` with improved signature compared to the old
version in `skimage.data`. This replaces the old `length` and `n_dim` arguments with
a single `shape` argument. This allows generating images with varying
dimension lengths. The old version is now a simple wrapper around the
implementation in `skimage2`.

Also, add `skimage._shared._warnings.warn_external` which
automatically sets the correct stacklevel for warnings.

Co-authored-by: Stefan van der Walt <[email protected]>
Co-authored-by: Juan Nunez-Iglesias <[email protected]>
Co-authored-by: Marianne Corvellec <[email protected]>
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" 🔧 type: Maintenance Refactoring and maintenance of internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconsider signature of binary_blobs

6 participants