MONAI icon indicating copy to clipboard operation
MONAI copied to clipboard

Fix type hint for image reader

Open Kirscher opened this issue 1 month ago โ€ข 3 comments

Description

This PR fixes the type hint for image reader to correctly handle Cupy arrays and removes the TODO.

Types of changes

  • [x] Non-breaking change (fix or new feature that would not break existing functionality).

Kirscher avatar Nov 30 '25 16:11 Kirscher

Walkthrough

The change adds a NdarrayOrCupy type alias in monai/data/image_reader.py (defined under a TYPE_CHECKING block to reference cupy.ndarray when available, falling back otherwise) and imports Union. Type annotations for internal image data containers are updated from list[np.ndarray] to list[NdarrayOrCupy] in the relevant get_data implementations. No runtime logic is changed; this is a static typing update to allow NumPy or CuPy arrays.

Estimated code review effort

๐ŸŽฏ 2 (Simple) | โฑ๏ธ ~8 minutes

  • Homogeneous, localized annotation changes in a single file
  • Verify TYPE_CHECKING block and alias resolve correctly and do not introduce runtime dependency
  • Confirm Union import and any added typing imports are used and lint-clean

Pre-merge checks and finishing touches

โœ… Passed checks (3 passed)
Check name Status Explanation
Title check โœ… Passed The title accurately describes the main change: updating type hints in the image reader to support CuPy arrays.
Description check โœ… Passed Description covers the change objective and marks it as non-breaking, but lacks detail about the specific implementation and omits testing sections.
Docstring Coverage โœ… Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

๐Ÿ“œ Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between e242c44aacde722a070773bc5633bbffe35bfa87 and 1a58715442f3a7b1e3ea86271bec7e61d7691c67.

๐Ÿ“’ Files selected for processing (1)
  • monai/data/image_reader.py (4 hunks)
๐Ÿšง Files skipped from review as they are similar to previous changes (1)
  • monai/data/image_reader.py

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.

coderabbitai[bot] avatar Nov 30 '25 16:11 coderabbitai[bot]

/build

KumoLiu avatar Dec 05 '25 15:12 KumoLiu

Hi @KumoLiu The packaging test is failing when running out of space, is this possibly related to #7901? I remember this was solved with the fix where we clean out some things in the image being used.

ericspod avatar Dec 05 '25 20:12 ericspod