Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#9,135 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python, pytorch

Research direction

Start with SlidingPatchWSIDataset and MaskedPatchWSIDataset, comparing how each builds ProbMapKeys.LOCATION, then inspect the indexing in monai/handlers/probability_maps.py. Reproduce with NumPy 2.x using the provided snippet and sliding-window inference; done means the location metadata has an integer dtype and ProbMapProducer indexes the probability map without IndexError.

Written by the indexing model from the issue text.

Description

Describe the bug

SlidingPatchWSIDataset builds ProbMapKeys.LOCATION with np.round(...) and never casts back to int, so the metadata is float64. ProbMapProducer uses it directly as an array index, which numpy 2.x rejects:

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`)
and integer or boolean arrays are valid indices

MaskedPatchWSIDataset already calls .astype(int) on the same key, so the two datasets emit different dtypes.

To Reproduce

Steps to reproduce the behavior:

To Reproduce

Steps to reproduce the behavior:

  1. Install: pip install "monai==1.6.1" "numpy>=2.0" torch tifffile
  2. Run:
    import numpy as np, tifffile, tempfile, os
    from monai.data import SlidingPatchWSIDataset
    from monai.utils.enums import WSIPatchKeys, ProbMapKeys
    
    path = os.path.join(tempfile.mkdtemp(), "slide.tiff")
    tifffile.imwrite(path, np.random.randint(0, 255, (4, 4, 3), dtype=np.uint8), photometric="rgb")
    
    ds = SlidingPatchWSIDataset(
        data=[{"image": path, WSIPatchKeys.LEVEL: 0}], patch_size=(2, 2), reader="TiffFile")
    print(ds.data[0][ProbMapKeys.LOCATION.value].dtype)
    
    Output: float64 (expected an integer dtype)
  3. Run sliding-window WSI inference with ProbMapProducer attached. It raises at monai/handlers/probability_maps.py:
    self.prob_map[name][tuple(loc)] = prob
    

Expected behavior

ProbMapKeys.LOCATION should be an integer array, consistent with MaskedPatchWSIDataset, and ProbMapProducer should index the probability map without error.

Screenshots

N/A — traceback included above.

Environment

MONAI version: 1.6.1
Numpy version: 2.5.3
Pytorch version: 2.14.0+cpu
MONAI flags: HAS_EXT=False, USE_COMPILED=False, USE_META_DICT=False
MONAI rev id: 7af492176792f9069b8f1253d099abd05c5e769d

System: Linux
Linux version: Ubuntu 24.04 LTS
Platform: Linux-6.8.0-31-generic-x86_64-with-glibc2.39
Python version: 3.12.3

Minimal venv for reproducing against a released wheel, so optional dependencies report NOT INSTALLED.

Dominant language
Python
Stars
8.7k
Forks
1.6k
Avg merge
3d 10h
Merged PRs (30d)
17

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Project-MONAI/MONAI

All issues in Project-MONAI/MONAI

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.