Fix: make y optional in ignore_background
Fixes # .
Description
This PR addresses a TODO in monai/metrics/active_learning_metrics.py by making the y argument optional in the ignore_background utility function. This allows for cleaner code when only y_pred needs to be processed, as seen in active_learning_metrics.py.
Types of changes
- [x] Non-breaking change (fix or new feature that would not break existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running
./runtests.sh -f -u --net --coverage. - [x] Quick tests passed locally by running
./runtests.sh --quick --unittests --disttests. - [ ] In-line docstrings updated.
- [ ] Documentation updated, tested
make htmlcommand in thedocs/folder.
Walkthrough
The ignore_background function in monai/metrics/utils.py now accepts an optional y parameter (defaulting to None) with updated return type tuple[NdarrayTensor, NdarrayTensor | None]. The calling code in monai/metrics/active_learning_metrics.py passes y=None to ignore_background when include_background is False, discarding the second return value.
Estimated code review effort
🎯 1 (Trivial) | ⏱️ ~5 minutes
- Focused change across 2 files
- Straightforward parameter signature update with None guard
- Consistent calling pattern change
- No complex logic modifications
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | Title clearly and concisely describes the main change: making the y parameter optional in ignore_background function. |
| Description check | ✅ Passed | Description covers the core change, rationale, and test coverage. Author marked test addition and quick tests passing, though integration tests and docstring updates are unchecked. |
| 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
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.