Skip to content

fix: add missing stacklevel=2 to warnings.warn() calls #1164

Description

@rtmalikian

Problem

15 warnings.warn() calls across the codebase are missing the stacklevel parameter. Without stacklevel=2, warnings point to library internals instead of the user's code, making them confusing and hard to act on.

Affected Files

  • pyhealth/data/__init__.py — 1 call
  • pyhealth/datasets/__init__.py — 4 calls
  • pyhealth/datasets/mimic3.py — 1 call
  • pyhealth/datasets/mimic4.py — 2 calls
  • pyhealth/metrics/interpretability/evaluator.py — 1 call
  • pyhealth/models/concare.py — 1 call
  • pyhealth/models/stagenet.py — 2 calls
  • pyhealth/models/stagenet_mha.py — 2 calls
  • pyhealth/models/text_embedding.py — 1 call

Proposed Fix

Add stacklevel=2 to all 15 calls so warnings correctly point to the caller's code.

Verification

python3 -c "import ast, os; [ast.parse(open(os.path.join(r,f)).read()) for r,d,fs in os.walk('pyhealth') for f in fs if f.endswith('.py')]"

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