Fix type hint for image reader
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).
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_CHECKINGblock and alias resolve correctly and do not introduce runtime dependency - Confirm
Unionimport 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
/build
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.