Raise OptionalImportError for unavailable explicit image readers - #9006
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/transforms/test_load_image.py`:
- Around line 231-233: Update the warnings.catch_warnings context in the
LoadImage missing-reader test to call warnings.simplefilter("always") before
constructing LoadImage, ensuring the emitted warning is captured regardless of
existing filters while preserving the OptionalImportError assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9f59df5e-f5b9-431f-93ac-2088870e0dfa
📒 Files selected for processing (3)
monai/transforms/io/array.pytests/data/test_init_reader.pytests/transforms/test_load_image.py
vikashg
left a comment
There was a problem hiding this comment.
Minimal and correct change — except OptionalImportError: raise is exactly the right fix. The "fail loud for explicit requests, fall back for auto-selection" semantic matches user intent. Mock-based tests ensure environment independence. All CI green. LGTM.
|
Hi maintainers, just a gentle follow-up on this PR. The CI is green, and the current implementation has received an approval. Since another PR addressing the same issue was recently opened as #9039, I wanted to ask whether you could review the two approaches when convenient. This PR was opened earlier and uses environment-independent mocked readers for regression coverage, while preserving automatic reader selection and runtime fallback behavior. I’m happy to make any requested changes, rebase, or incorporate any preferred aspects of the alternative implementation. Thank you! |
|
@minsuking its approved. |
|
Hi @minsuking, this branch contains a merge commit which isn't allowed by the repo's branch protection rules. Could you rebase onto git fetch upstream dev
git rebase upstream/dev
git push --force-with-lease(Replace |
Signed-off-by: Minsu Kim <minsu.kim08@gmail.com>
Signed-off-by: Minsu Kim <minsu.kim08@gmail.com>
Head branch was pushed to by a user without write access
c6d29d6 to
ea03f96
Compare
|
@vikashg Thanks for the guidance. I’ve rebased the branch onto the latest |
|
Thanks |
Description
Fixes #7437.
When
LoadImageis given an explicit reader string whose optional dependency is unavailable, the originalOptionalImportErroris now propagated instead of being converted into a warning and silently falling back to another registered reader.Automatic reader selection with
reader=Noneremains unchanged.Implementation
OptionalImportErrorfor explicitly requested unavailable string readers.Compatibility
This is an intentional behavior change for explicitly requested unavailable readers.
The following behavior remains unchanged:
reader=NoneThis PR does not redesign explicit tuple/list reader semantics.
Validation
Executed locally:
python -m tests.transforms.test_load_imagepython -m tests.transforms.test_load_imagedpython -m tests.data.test_init_readerAll executed tests passed.
Some optional-backend tests were skipped as expected in the current environment.