Skip to content

fix: add missing stacklevel=2 to warnings.warn() calls in losses/ #8929

Closed

Description

@rtmalikian

Problem

28 calls to warnings.warn() in monai/losses/ are missing the stacklevel parameter. Without stacklevel=2, warnings point to the MONAI internal code instead of the user's calling code, making it difficult for users to identify which part of their script triggered the warning.

Proposed Fix

Add stacklevel=2 to all 28 warnings.warn() calls in:

  • monai/losses/dice.py (7 instances)
  • monai/losses/tversky.py (3 instances)
  • monai/losses/mcc_loss.py (3 instances)
  • monai/losses/focal_loss.py (3 instances)
  • monai/losses/hausdorff_loss.py (3 instances)
  • monai/losses/unified_focal_loss.py (3 instances)
  • monai/losses/spatial_mask.py (3 instances)
  • monai/losses/perceptual.py (2 instances)
  • monai/losses/adversarial_loss.py (1 instance)

Affected Files

  • monai/losses/dice.py
  • monai/losses/tversky.py
  • monai/losses/mcc_loss.py
  • monai/losses/focal_loss.py
  • monai/losses/hausdorff_loss.py
  • monai/losses/unified_focal_loss.py
  • monai/losses/spatial_mask.py
  • monai/losses/perceptual.py
  • monai/losses/adversarial_loss.py

Activity

  1. added a commit that references this issue on Jun 26, 2026
    5e42fbf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions