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')]"
Problem
15
warnings.warn()calls across the codebase are missing thestacklevelparameter. Withoutstacklevel=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 callpyhealth/datasets/__init__.py— 4 callspyhealth/datasets/mimic3.py— 1 callpyhealth/datasets/mimic4.py— 2 callspyhealth/metrics/interpretability/evaluator.py— 1 callpyhealth/models/concare.py— 1 callpyhealth/models/stagenet.py— 2 callspyhealth/models/stagenet_mha.py— 2 callspyhealth/models/text_embedding.py— 1 callProposed Fix
Add
stacklevel=2to 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')]"