Skip to content

Restore original behavior of min_size in remove_small_* during its deprecation#8003

Merged
lagru merged 6 commits intoscikit-image:mainfrom
lagru:fix-rm-small-obj-min-size-depr
Jan 14, 2026
Merged

Restore original behavior of min_size in remove_small_* during its deprecation#8003
lagru merged 6 commits intoscikit-image:mainfrom
lagru:fix-rm-small-obj-min-size-depr

Conversation

@lagru
Copy link
Copy Markdown
Member

@lagru lagru commented Jan 6, 2026

Description

Fixes #8001

The renaming of min_size/area_threshold to max_size in #7739 was actually accompanied by a change in behaviour for the same value, due to using > in the old nomenclature and >= in the new one.

Unfortunately our deprecation machinery was until now not smart enough to know whether a renamed parameter was provided under its old name or its new name. To address this, this PR:

  • Updates the deprecation machinery to detect when a parameter was given with the old name/position, and
  • Uses this updated machinery to modify min_size/area_threshold by 1 to ensure that the new behaviour matches the old one.

Checklist

Release note

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

In `skimage.morphology`, fix an unintended change in deprecated behavior in
`remove_small_objects` and `remove_small_holes`. The deprecation of the 
parameters `min_size` and `area_threshold` introduced an off-by-one error when
using them.

lagru added 2 commits January 6, 2026 17:12
to signal that a deprecated parameter received a value that was
forwarded to the new parameter. This allows correcting for potentially
changed behavior between deprecated and new parameter.
The deprecation accidentally changed the behavior of the deprecated
`min_size`. However, the original behavior should stay available during
the deprecation period! This fixes that.

Furthermore, the new default must be `max_size=63` to be equivalent to
the old `min_size=64`.
@lagru lagru added the 🩹 type: Bug fix Fixes unexpected or incorrect behavior label Jan 6, 2026
@jmuhlich
Copy link
Copy Markdown
Contributor

jmuhlich commented Jan 6, 2026

I submitted a PR against your feature branch that fixes some failing tests. I thought it would be easier that way than to add a code review comment explaining the changes!

@lagru lagru marked this pull request as ready for review January 8, 2026 11:43
@lagru lagru changed the title Restore original behavior of min_size in remove_small_objects during its deprecation Restore original behavior of min_size in remove_small_* during its deprecation Jan 13, 2026
Copy link
Copy Markdown
Member

@jni jni left a comment

Choose a reason for hiding this comment

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

Clever. Maybe too clever 😂 but I'll allow it. 😂 Thanks @lagru!

@jni
Copy link
Copy Markdown
Member

jni commented Jan 14, 2026

(And thank you @jmuhlich for the report and for contributing to this fix! 🙏)

@jni
Copy link
Copy Markdown
Member

jni commented Jan 14, 2026

@lagru Want to update the description before merging? I like to have the final commit message describe the problem and fix more fully than just GH links. Example:

Fixes #8001

The renaming of min_size/area_threshold to max_size in #7739 was actually accompanied by a change in behaviour for the same value, due to using > in the old nomenclature and >= in the new one.

Unfortunately our deprecation machinery was until now not smart enough to know whether a renamed parameter was provided under its old name or its new name. To address this, this PR:

  1. Updates the deprecation machinery to detect when a parameter was given with the old name/position, and
  2. Uses this updated machinery to modify min_size/area_threshold by 1 to ensure that the new behaviour matches the old one.

@lagru
Copy link
Copy Markdown
Member Author

lagru commented Jan 14, 2026

Done. I'll just merge right now.

@lagru lagru merged commit dc02027 into scikit-image:main Jan 14, 2026
25 checks passed
@stefanv stefanv added this to the 0.27 milestone Jan 14, 2026
@lagru lagru deleted the fix-rm-small-obj-min-size-depr branch January 14, 2026 12:36
@lagru
Copy link
Copy Markdown
Member Author

lagru commented Jan 14, 2026

Feel welcome to edit the release note in the PR description further if you want. :)

@lagru
Copy link
Copy Markdown
Member Author

lagru commented Jan 14, 2026

Clever. Maybe too clever 😂 but I'll allow it. 😂

Yeah, I feel like that decorator is getting out of hand. If we had infinite time, I'd just refactor and split it for the different use cases.

Copy link
Copy Markdown
Member

@stefanv stefanv left a comment

Choose a reason for hiding this comment

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

Darnit; I reviewed this a while ago and forgot to press "submit" 🤦

This is useful if ``None`` is already used for a different purpose or just
to highlight a deprecated parameter in the signature.

This is a sentinel and not meant to be initialized.
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.

Suggested change
This is a sentinel and not meant to be initialized.
This is a sentinel and is not meant to be initialized.

"""


class DEPRECATED_GOT_VALUE(metaclass=PatchClassRepr):
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.

Since this is internal, I'd opt for a descriptive name: DEPRECATED_BUT_RECEIVED_VALUE or DEPRECATED_BUT_SET_BY_USER.

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.

Actually, looking at the code below, another way to spell this would simply be RECEIVED_VALUE or SET_BY_USER, since it is used on the module: deprecate_parameter.SET_BY_USER or deprecate_paramer.RECEIVED_VALUE. (Would read better as deprecated_parameter.)

)
def remove_small_objects(
ar, min_size=DEPRECATED, connectivity=1, *, max_size=64, out=None
ar, min_size=DEPRECATED, connectivity=1, *, max_size=63, out=None
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.

Did this change inadvertently?

@stefanv
Copy link
Copy Markdown
Member

stefanv commented Jan 14, 2026

No action needed on my late submission review; I'll make a PR for quick review, which you can choose to accept or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🩹 type: Bug fix Fixes unexpected or incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deprecation of remove_small_objects min_size arg does not preserve original behavior

4 participants