Skip to content

Allow read-only arrays as input to remap#7535

Merged
lagru merged 7 commits intoscikit-image:mainfrom
stefanv:const-remap
Feb 8, 2026
Merged

Allow read-only arrays as input to remap#7535
lagru merged 7 commits intoscikit-image:mainfrom
stefanv:const-remap

Conversation

@stefanv
Copy link
Copy Markdown
Member

@stefanv stefanv commented Sep 9, 2024

Closes #6378.

This requires adding consts across a much larger portion of our Cython code, but this WIP illustrates how it can be done.

Release note

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

In `skimage.util.map_array`, allow read-only arrays 
(`WRITEABLE` flag set to `False`) as input to the parameters
`input_arr`, `input_vals`, and `output_vals`.

@stefanv stefanv added the 🩹 type: Bug fix Fixes unexpected or incorrect behavior label Sep 9, 2024
@lagru
Copy link
Copy Markdown
Member

lagru commented Sep 17, 2024

Is this ready for review? I feel like we should add a test for this right?

@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the 😴 Dormant No recent activity label Mar 17, 2025
@galenlynch
Copy link
Copy Markdown

Would love to see a similar change made to marching_cubes.

@github-actions github-actions bot removed the 😴 Dormant No recent activity label Apr 8, 2025
jni added a commit to jni/skan that referenced this pull request Feb 6, 2026
jni added a commit to jni/skan that referenced this pull request Feb 6, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Bumped minimum Cython from 3.0.8 to 3.0.10 in build configs, added const qualifiers to _map_array input parameters, and added a parameterized test verifying behavior with read-only input/output arrays.

Changes

Cohort / File(s) Summary
Dependency Version Updates
environment.yml, pyproject.toml, requirements/build.txt
Bumped minimum Cython requirement from >=3.0.8 to >=3.0.10 (kept !=3.2.0b1) in build and requirement files.
Function Signature
src/skimage/util/_remap.pyx
Updated _map_array signature to add const qualifiers for inarr, inval, and outval, enforcing immutability of those inputs.
Test Coverage
tests/skimage/util/test_map_array.py
Added itertools import and test_map_array_read_only, parameterized over writable/read-only combinations; verifies read-only inputs are accepted and a read-only output raises ValueError.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: allowing read-only arrays as input to the remap function, which is evidenced by the const qualifiers added to function parameters and the new test validating read-only input handling.
Description check ✅ Passed The PR description clearly relates to the changeset, explaining the need to allow read-only arrays in skimage.util.map_array by adding const qualifiers.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pyproject.toml (1)

123-131: ⚠️ Potential issue | 🔴 Critical

[build-system] Cython version not updated — build may fail with const memoryview syntax.

Line 127 still pins Cython>=3.0.8, while [project.optional-dependencies] build (line 51) was bumped to >=3.0.10. The comment on line 48 explicitly warns to keep these in sync. Since the const memoryview qualifier in _remap.pyx requires ≥3.0.10, a build using only [build-system] requirements (e.g., pip install .) could pick Cython 3.0.8/3.0.9 and fail to compile.

Proposed fix
 [build-system]
 build-backend = 'mesonpy'
 requires = [
     'meson-python>=0.16',
-    'Cython>=3.0.8,!=3.2.0b1',
+    'Cython>=3.0.10,!=3.2.0b1',
     'pythran>=0.16',
     'lazy_loader>=0.4',
     'numpy>=2.0',
 ]

@jni
Copy link
Copy Markdown
Member

jni commented Feb 6, 2026

@lagru @stefanv I just ran into this in jni/skan#256 (and have heard of several other cases, just didn't have time to investigate), so I am hoping to revive this. 😊 I've merged in main, added some tests, and pushed to @stefanv's branch, so I hope this is good to go! I'm going to approve but another read through by @lagru would be appreciated! 😊

@jni
Copy link
Copy Markdown
Member

jni commented Feb 6, 2026

@galenlynch thanks for chiming in! We should definitely do this for many of our Cython functions, but we should probably keep PRs small to help get them in quickly. If you would like to directly contribute a fix for marching cubes, we would appreciate it, otherwise, we'll make a follow-up issue and get to it when we can... 😅 As you have seen it can take a while, but we do eventually get to things... 😅

@lagru lagru self-requested a review February 8, 2026 16:00
Copy link
Copy Markdown
Member

@lagru lagru left a comment

Choose a reason for hiding this comment

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

I couldn't help but tweak the test a little bit since I had it checked out anyway.

Will merge if CI stays green. Thanks everyone. 😊

@lagru lagru merged commit 70ab2a6 into scikit-image:main Feb 8, 2026
35 of 37 checks passed
@lagru lagru added this to the 0.27 milestone Feb 8, 2026
matthew-brett added a commit that referenced this pull request Apr 10, 2026
* origin/main: (27 commits)
  Move `_shared` to `_skimage2` (#8102)
  Port `pad_footprint` & `mirror_footprint` to `skimage2` (#8094)
  Add rescaling API to skimage2 (#8075)
  Move `skimage2` implementation into `_skimage2` (#8093)
  Undo (double) mirroring in `ski2.morphology.dilation` (#8060)
  Grammar (#8091)
  Move `ensure_spacing` into `skimage2` (#8067)
  Ensure that `skimage2` does not eagerly import `skimage` (#8087)
  Use lazy-loader 0.5 (#8080)
  MAINT: make ellipse fitting forward compatible  (#8054)
  Avoid deprecated assign to ndarray.shape (#8020)
  Avoid circular import in `feature/corner.py` (#8077)
  Turn off coderabbit auto-labeling & label checks (#8070)
  Fix GIL being re-enabled by C++ extensions (#8059)
  Fix conventions following docstub and misc. (#8055)
  Port grayscale morphology operators to skimage2 (#8046)
  Add revised `peak_local_max` to `skimage2` (#8039)
  Allow read-only arrays as input to remap (#7535)
  Add `prescale`  parameter to "blob functions" (#7858)
  Try to make coderabbit respect exisiting type labels (#8042)
  ...
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.

utils.map_array: error for non-writeable input arrays

4 participants