Skip to content

Cast SlidingPatchWSIDataset mask locations to int - #9170

Open
caitlin-leonard wants to merge 1 commit into
Project-MONAI:devfrom
caitlin-leonard:fix-sliding-patch-int-locations
Open

caitlin-leonard wants to merge 1 commit into
Project-MONAI:devfrom
caitlin-leonard:fix-sliding-patch-int-locations

Conversation

@caitlin-leonard

Copy link
Copy Markdown
Contributor

Fixes #9135.

Description

SlidingPatchWSIDataset computes each patch's mask location with
np.round(...), which rounds the values but keeps them as floats.
ProbMapProducer then uses these locations as array indices, which
raises an IndexError on NumPy 2.x.

This adds .astype(int) to that calculation, matching what
MaskedPatchWSIDataset already does for the same key.

The test change adds an assertion to test_read_patches_large that the
mask location dtype is an integer. It fails on dev (the values are
floats) and passes with this change.

Tested locally with the OpenSlide backend:
tests/data/test_sliding_patch_wsi_dataset.py,
test_masked_patch_wsi_dataset.py, test_patch_wsi_dataset.py and
tests/handlers/test_handler_prob_map_producer.py.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.

Fixes Project-MONAI#9135

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Caitlin Leonard <caitlinsimona@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Project-MONAI/MONAI/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 13ea663f-ceb9-473f-bbea-23e5cb9579a0
📥 Commits

Reviewing files that changed from the base of the PR and between 03e208f and af77369.

📒 Files selected for processing (2)
  • monai/data/wsi_datasets.py
  • tests/data/test_sliding_patch_wsi_dataset.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

SlidingPatchWSIDataset now casts rounded, downsampled patch-center coordinates to integers. The large-patch test checks that each sample’s probability-map location metadata has an integer dtype.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~5 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to af773

The dataset now emits integer mask locations for the probability-map indexing path, and the added test checks that dtype. No actionable merge-blocking risk is evident in this change.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: casting mask locations to integers in SlidingPatchWSIDataset.
Description check Passed The description explains the NumPy 2.x issue, the code change, the added test, and the local validation. It includes the issue reference, change description, and applicable change type.
Linked Issues check Passed Issue #9135 requires integer ProbMapKeys.LOCATION values from SlidingPatchWSIDataset. The change applies .astype(int) after np.round(...) in SlidingPatchWSIDataset._evaluate_patch_locations.…
Out of Scope Changes check Passed The reported changes contain one production fix in monai/data/wsi_datasets.py and one focused test update in tests/data/test_sliding_patch_wsi_dataset.py. Both changes directly support issue #9135…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

This branch has not been deployed

No deployments
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.

ProbMapProducer raises IndexError on numpy 2.x: SlidingPatchWSIDataset emits float locations

1 participant