Skip to content

fix(segmentation): use np.isin in clear_border (np.in1d removed in numpy ≥2.2)#43

Merged
alxndrkalinin merged 1 commit into
mainfrom
fix/clear-border-np-isin
May 29, 2026
Merged

fix(segmentation): use np.isin in clear_border (np.in1d removed in numpy ≥2.2)#43
alxndrkalinin merged 1 commit into
mainfrom
fix/clear-border-np-isin

Conversation

@alxndrkalinin

@alxndrkalinin alxndrkalinin commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

cubic/segmentation/_clear_border.py:120 calls np.in1d, which was deprecated in numpy 1.25 and removed in numpy 2.2. Replaces with np.isin, the drop-in successor.

For the 1-D indices = np.arange(number + 1) array used here, the two functions are behaviorally identical (np.in1d always flattens its output; np.isin preserves input shape — both produce the same 1-D mask when the input is already 1-D).

Test plan

  • All 3 existing clear_border tests pass (tests/segmentation/test_clear_border.py)
  • Manual smoke test: a border-touching label is cleared, an interior label is preserved

🤖 Generated with Claude Code

Summary by Sourcery

Bug Fixes:

  • Use np.isin instead of removed np.in1d in clear_border to restore compatibility with NumPy 2.2 and later.

…mpy ≥2.2)

np.in1d was deprecated in numpy 1.25 and removed in numpy 2.2. np.isin is
the drop-in replacement; for the 1-D indices array used here the two are
behaviorally identical (np.in1d always flattens, np.isin preserves shape,
and indices is already 1-D from np.arange).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces the deprecated and removed NumPy np.in1d call in clear_border with np.isin to maintain compatibility with NumPy ≥2.2 while preserving behavior for the 1-D indices array.

File-Level Changes

Change Details Files
Update clear_border border-label masking to use np.isin instead of deprecated np.in1d for NumPy ≥2.2 compatibility.
  • Replace np.in1d call used to compute label_mask with np.isin, which is behaviorally equivalent for the 1-D indices array.
  • Keep the surrounding label index generation and mask reshaping logic unchanged to ensure the same label clearing semantics.
cubic/segmentation/_clear_border.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Since indices is created with xp.arange, consider using the corresponding backend-specific isin (or keeping this consistently on the xp namespace) to avoid potential device/array-type mismatches when xp is not NumPy.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since `indices` is created with `xp.arange`, consider using the corresponding backend-specific `isin` (or keeping this consistently on the `xp` namespace) to avoid potential device/array-type mismatches when `xp` is not NumPy.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@alxndrkalinin alxndrkalinin merged commit 4bca3a1 into main May 29, 2026
9 checks passed
@alxndrkalinin alxndrkalinin deleted the fix/clear-border-np-isin branch May 29, 2026 00:57
alxndrkalinin added a commit that referenced this pull request Jun 1, 2026
Resets the version after v0.7.0a8/a9/a10 tags were deleted before
publish. Covers PRs #42, #43, #44, #45, and #46 on top of v0.7.0a7.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant