Skip to content

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

Open
rtmalikian wants to merge 1 commit into
sunlabuiuc:masterfrom
rtmalikian:fix/issue-1164-missing-stacklevel
Open

fix: add missing stacklevel=2 to 14 warnings.warn() calls (Fixes #1164)#1165
rtmalikian wants to merge 1 commit into
sunlabuiuc:masterfrom
rtmalikian:fix/issue-1164-missing-stacklevel

Conversation

@rtmalikian

Copy link
Copy Markdown

Fixes #1164

Summary

Add stacklevel=2 to 14 warnings.warn() calls across 8 files that were missing it. Without stacklevel=2, warnings point to library internals instead of the user's code, making them confusing and hard to act on.

Changes

File Calls Fixed Warning Context
pyhealth/data/__init__.py 1 Visit class deprecation
pyhealth/datasets/__init__.py 4 BaseEHRDataset, BaseSignalDataset, SampleEHRDataset, SampleSignalDataset deprecations
pyhealth/datasets/mimic3.py 1 Prescriptions table date-only timestamps
pyhealth/datasets/mimic4.py 2 Discharge/discharge_detail table date-only timestamps
pyhealth/models/concare.py 1 Nested sequence vocab_size warning
pyhealth/models/stagenet.py 2 Missing time intervals and mask warnings
pyhealth/models/stagenet_mha.py 2 Missing time intervals and mask warnings
pyhealth/models/text_embedding.py 1 Text chunk truncation warning

Verification

# Syntax check all modified files
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')]"

# Verify all warnings.warn() calls have stacklevel
python3 -c "
import ast, os
for r, d, fs in os.walk('pyhealth'):
    for f in fs:
        if f.endswith('.py'):
            tree = ast.parse(open(os.path.join(r,f)).read())
            for node in ast.walk(tree):
                if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr == 'warn':
                    assert any(kw.arg == 'stacklevel' for kw in node.keywords), f'{os.path.join(r,f)}:{node.lineno}'
print('All warnings.warn() calls have stacklevel')
"

Changelog

Date Change Author
2026-06-20 Add stacklevel=2 to 14 warnings.warn() calls across 8 files rtmalikian

About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.

📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a


Disclosure: This code was developed with assistance from mimo-v2.5-pro (Xiaomi) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.

Add stacklevel=2 to all warnings.warn() calls that were missing it,
so warnings correctly point to the caller's code instead of library
internals.

Affected files:
- pyhealth/data/__init__.py — 1 call (Visit deprecation)
- pyhealth/datasets/__init__.py — 4 calls (deprecated dataset classes)
- pyhealth/datasets/mimic3.py — 1 call (prescriptions timestamp)
- pyhealth/datasets/mimic4.py — 2 calls (discharge timestamps)
- pyhealth/models/concare.py — 1 call (nested_sequence warning)
- pyhealth/models/stagenet.py — 2 calls (time/mask warnings)
- pyhealth/models/stagenet_mha.py — 2 calls (time/mask warnings)
- pyhealth/models/text_embedding.py — 1 call (chunk truncation)

Fixes sunlabuiuc#1164

Signed-off-by: rtmalikian <rtmalikian@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant