fix(losses): add missing docstring entries for default parameters#8755
fix(losses): add missing docstring entries for default parameters#8755yushiran wants to merge 1 commit intoProject-MONAI:devfrom
Conversation
- Add missing `alpha` parameter (default 2.0) to HausdorffDTLoss.__init__ docstring - Add "Defaults to X" notes to SoftclDiceLoss and SoftDiceclDiceLoss docstrings for `iter_`, `smooth`, and `alpha` parameters Signed-off-by: Shiran Yu <shiran.yu@bristol.ac.uk>
📝 WalkthroughWalkthroughDocstring updates across two loss module files. SoftclDiceLoss and SoftDiceclDiceLoss docstrings now explicitly state default parameter values (iter_: 3, smooth: 1.0; iter_: 3, alpha: 0.5, smooth: 1.0). HausdorffDTLoss docstring documents the alpha parameter. No changes to function signatures, logic, or behavior. Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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.
Pull request overview
This PR adds missing and incomplete default parameter documentation to loss function docstrings, following the convention established in PR #8701. The changes are purely documentary with no code logic modifications.
Changes:
- Added missing
alphaparameter documentation toHausdorffDTLoss.__init__inhausdorff_loss.py - Updated parameter descriptions in
cldice.pyto include default values for better API documentation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| monai/losses/hausdorff_loss.py | Added missing docstring entry for alpha parameter (default 2.0) that was present in function signature but undocumented |
| monai/losses/cldice.py | Added "Defaults to X." to parameter descriptions for iter_, smooth, and alpha in SoftclDiceLoss and SoftDiceclDiceLoss classes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@monai/losses/cldice.py`:
- Around line 163-165: The docstring parameter list is out of order: the
function/class signature declares alpha before smooth, but the docstring lists
smooth first; update the docstring in monai/losses/cldice.py to list alpha
before smooth (and ensure the descriptions match the signature order for
parameters alpha and smooth, e.g., alpha: ... then smooth: ...), referencing the
initializer/function name (CLDice or its __init__/forward where the signature
appears) so the docstring aligns with the actual parameter order.
ℹ️ Review info
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
📒 Files selected for processing (2)
monai/losses/cldice.pymonai/losses/hausdorff_loss.py
| iter_: Number of iterations for skeletonization. Defaults to 3. | ||
| smooth: Smoothing parameter. Defaults to 1.0. | ||
| alpha: Weighing factor for cldice. Defaults to 0.5. |
There was a problem hiding this comment.
Docstring parameter order doesn't match the signature.
The signature declares alpha before smooth, but the docstring lists smooth first. Swap to keep them aligned.
📝 Proposed fix
Args:
iter_: Number of iterations for skeletonization. Defaults to 3.
- smooth: Smoothing parameter. Defaults to 1.0.
alpha: Weighing factor for cldice. Defaults to 0.5.
+ smooth: Smoothing parameter. Defaults to 1.0.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| iter_: Number of iterations for skeletonization. Defaults to 3. | |
| smooth: Smoothing parameter. Defaults to 1.0. | |
| alpha: Weighing factor for cldice. Defaults to 0.5. | |
| iter_: Number of iterations for skeletonization. Defaults to 3. | |
| alpha: Weighing factor for cldice. Defaults to 0.5. | |
| smooth: Smoothing parameter. Defaults to 1.0. |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@monai/losses/cldice.py` around lines 163 - 165, The docstring parameter list
is out of order: the function/class signature declares alpha before smooth, but
the docstring lists smooth first; update the docstring in monai/losses/cldice.py
to list alpha before smooth (and ensure the descriptions match the signature
order for parameters alpha and smooth, e.g., alpha: ... then smooth: ...),
referencing the initializer/function name (CLDice or its __init__/forward where
the signature appears) so the docstring aligns with the actual parameter order.
Description
Fixes missing and incomplete docstring parameter documentation in two loss files, consistent with the pattern established in #8701.
Changes
monai/losses/hausdorff_loss.pyHausdorffDTLoss.__init__: Added missingalphaparameter (default2.0) to theArgssection. The parameter was present in the function signature but completely absent from the docstring.monai/losses/cldice.pySoftclDiceLoss.__init__: AddedDefaults to X.toiter_andsmoothparameter descriptions.SoftDiceclDiceLoss.__init__: AddedDefaults to X.toiter_,smooth, andalphaparameter descriptions.Motivation
These are pure docstring fixes — no code logic was changed. The missing
alphadocumentation inHausdorffDTLossis the primary fix, and thecldice.pychanges follow the same "document defaults" pattern from #8701.Checklist