Skip to content

Deprecate old names & attributes in RegionProperties#7778

Merged
stefanv merged 2 commits intoscikit-image:mainfrom
lagru:deprecate-old-regionprops
May 2, 2025
Merged

Deprecate old names & attributes in RegionProperties#7778
stefanv merged 2 commits intoscikit-image:mainfrom
lagru:deprecate-old-regionprops

Conversation

@lagru
Copy link
Member

@lagru lagru commented Apr 22, 2025

Description

Closes #7732.

Checklist

Release note

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

Officially deprecate old properties in `skimage.measure.regionprops` and
related functions. While we removed the documentation for these some time
ago, they where still accessible as keys (via `__get_item__`) or attributes.
Going forward, using deprecated keys or attributes, will emit an
appropriate warning.

@lagru lagru added 🔽 Deprecation Involves deprecation 📜 type: API Involves API change(s) 🥾 Path to skimage2 A step towards the new "API 2.0" labels Apr 22, 2025
Comment on lines +426 to +427
# Fallback to default behavior, potentially raising an attribute error
return self.__getattribute__(attr)
Copy link
Member Author

Choose a reason for hiding this comment

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

{type(self)} would print <class 'skimage.measure._regionprops.RegionProperties'> here which isn't really what we want.


Aside: I noticed that something magically appends

Did you mean '...'

to the previous error message. Apparently only for properties. E.g.

class A:
    @property
    def a(self):
        return 3
    
    def __getattr__(self, item):
        raise AttributeError("not found")
    
A().A
[...] line 7, in __getattr__
    raise AttributeError("not found")
AttributeError: not found. Did you mean: 'a'

If that is official Python behavior I can't find a reference to this behavior? Am I crazy? 🤯

Copy link
Member

Choose a reason for hiding this comment

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

What version of Python are you seeing this on? I don't see it with 3.13.

Copy link
Member Author

Choose a reason for hiding this comment

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

Weird, I see it on 3.13.3 inside a simple repl:

Python 3.13.3 (main, Apr  9 2025, 07:44:25) [GCC 14.2.1 20250207] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
...     @property
...     def a(self):
...         return 3
...     
...     def __getattr__(self, item):
...         raise AttributeError("not found")
...     
... A().A
... 
Traceback (most recent call last):
  File "<python-input-0>", line 9, in <module>
    A().A
  File "<python-input-0>", line 7, in __getattr__
    raise AttributeError("not found")
AttributeError: not found. Did you mean: 'a'?

Copy link
Member

Choose a reason for hiding this comment

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

Haha, I have the same (i.e., AttributeError: not found. Did you mean: 'a'?) in Python 3.11.3... when I run spin python but not when I run spin ipython (I only get AttributeError: not found). 😅

Copy link
Member

Choose a reason for hiding this comment

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

Looks like Python 3.11 and 3.12 behavior.

Comment on lines 1577 to 1578
# lower case names in PROPS are still accessible as attributes
# Make sure those emit an appropriate warning
Copy link
Member Author

Choose a reason for hiding this comment

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

To do: clarify this comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

@stefanv, let me know if cabaf1a resolves this.

Don't really know why only lower-case properties were made accessible as attributes. Maybe that was introduced after the switch from camel case to snake case.

Comment on lines +426 to +427
# Fallback to default behavior, potentially raising an attribute error
return self.__getattribute__(attr)
Copy link
Member

Choose a reason for hiding this comment

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

Haha, I have the same (i.e., AttributeError: not found. Did you mean: 'a'?) in Python 3.11.3... when I run spin python but not when I run spin ipython (I only get AttributeError: not found). 😅

@stefanv stefanv merged commit 7ac3334 into scikit-image:main May 2, 2025
22 of 23 checks passed
@stefanv stefanv added this to the 0.26 milestone May 2, 2025
@lagru lagru deleted the deprecate-old-regionprops branch May 13, 2025 13:43
matthew-brett added a commit to matthew-brett/scikit-image that referenced this pull request Jul 7, 2025
* origin/main:
  Deprecate estimate method in favor of class constructor (scikit-image#7771)
  Temporary fix for Visual Studio & Clang incompatibility in Windows image (scikit-image#7835)
  Address deprecations in Pillow 11.3 (scikit-image#7828)
  Remove unused & obsolete `legacy_datasets`, `legacy_registry` vars (scikit-image#7677)
  Draft migration guide for skimage2 (scikit-image#7785)
  Do not report failure in wheels sub-recipe (scikit-image#7806)
  Use consistent wording in property description. (scikit-image#7804)
  Add intensity_median to regionprops (scikit-image#7745)
  CI: Update pypa/gh-action-pypi-publish to v1.12.4 for attestations on PyPI (scikit-image#7793)
  Document output dtype for transform.resize. (scikit-image#7792)
  Use `cibuildwheel` to build WASM/Pyodide wheels for `scikit-image`, push nightlies to Anaconda.org (scikit-image#7440)
  DOC: Include missing gain parameter in adjust_gamma equation (scikit-image#7763)
  Temporarily pin to `pyodide-build==0.30.0`, and ensure that the correct xbuildenvs are used (scikit-image#7788)
  Deprecate old names & attributes in RegionProperties (scikit-image#7778)
  Pin JasonEtco/create-an-issue action to SHA for v2.9.2 (scikit-image#7787)
  Make doctest-plus work with spin (scikit-image#7786)
  Report failures on main via issue (scikit-image#7752)
  Use `workers` instead of alternate parameter names (scikit-image#7302)
  Fix f-string in otsu plot (scikit-image#7780)
  Further document use of regionprops function and fix terms. (scikit-image#7518)
matthew-brett added a commit to matthew-brett/scikit-image that referenced this pull request Jul 14, 2025
* origin/main: (31 commits)
  Update import convention in certain gallery examples (scikit-image#7764)
  Refactor fundamental matrix scaling (scikit-image#7767)
  Add unit test for cval unequal to zero
  Forward  in _generic_edge_filter
  Remove superfluous mask argument from _generic_edge_filter
  Only report failure on main branch once
  Deprecate estimate method in favor of class constructor (scikit-image#7771)
  Temporary fix for Visual Studio & Clang incompatibility in Windows image (scikit-image#7835)
  Address deprecations in Pillow 11.3 (scikit-image#7828)
  Remove unused & obsolete `legacy_datasets`, `legacy_registry` vars (scikit-image#7677)
  Draft migration guide for skimage2 (scikit-image#7785)
  Do not report failure in wheels sub-recipe (scikit-image#7806)
  Use consistent wording in property description. (scikit-image#7804)
  Add intensity_median to regionprops (scikit-image#7745)
  CI: Update pypa/gh-action-pypi-publish to v1.12.4 for attestations on PyPI (scikit-image#7793)
  Document output dtype for transform.resize. (scikit-image#7792)
  Use `cibuildwheel` to build WASM/Pyodide wheels for `scikit-image`, push nightlies to Anaconda.org (scikit-image#7440)
  DOC: Include missing gain parameter in adjust_gamma equation (scikit-image#7763)
  Temporarily pin to `pyodide-build==0.30.0`, and ensure that the correct xbuildenvs are used (scikit-image#7788)
  Deprecate old names & attributes in RegionProperties (scikit-image#7778)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔽 Deprecation Involves deprecation 🥾 Path to skimage2 A step towards the new "API 2.0" 📜 type: API Involves API change(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecate old regionprop names

3 participants