diff --git a/pyhealth/data/__init__.py b/pyhealth/data/__init__.py index 1cf916bfe..ed8bf8d87 100755 --- a/pyhealth/data/__init__.py +++ b/pyhealth/data/__init__.py @@ -5,4 +5,4 @@ class Visit: """This class is deprecated and should not be used.""" def __init__(self, *args, **kwargs): import warnings - warnings.warn("The Visit class is deprecated and will be removed in a future version.", DeprecationWarning) \ No newline at end of file + warnings.warn("The Visit class is deprecated and will be removed in a future version.", DeprecationWarning, stacklevel=2) \ No newline at end of file diff --git a/pyhealth/datasets/__init__.py b/pyhealth/datasets/__init__.py index c29955e7d..6835363d7 100644 --- a/pyhealth/datasets/__init__.py +++ b/pyhealth/datasets/__init__.py @@ -7,6 +7,7 @@ def __init__(self, *args, **kwargs): warnings.warn( "The BaseEHRDataset class is deprecated and will be removed in a future version.", DeprecationWarning, + stacklevel=2, ) @@ -19,6 +20,7 @@ def __init__(self, *args, **kwargs): warnings.warn( "The BaseSignalDataset class is deprecated and will be removed in a future version.", DeprecationWarning, + stacklevel=2, ) @@ -31,6 +33,7 @@ def __init__(self, *args, **kwargs): warnings.warn( "The SampleEHRDataset class is deprecated and will be removed in a future version.", DeprecationWarning, + stacklevel=2, ) @@ -43,6 +46,7 @@ def __init__(self, *args, **kwargs): warnings.warn( "The SampleSignalDataset class is deprecated and will be removed in a future version.", DeprecationWarning, + stacklevel=2, ) diff --git a/pyhealth/datasets/mimic3.py b/pyhealth/datasets/mimic3.py index 7e569d2f3..150db2892 100644 --- a/pyhealth/datasets/mimic3.py +++ b/pyhealth/datasets/mimic3.py @@ -60,6 +60,7 @@ def __init__( "Events from prescriptions table only have date timestamp (no specific time). " "This may affect temporal ordering of events.", UserWarning, + stacklevel=2, ) super().__init__( root=root, diff --git a/pyhealth/datasets/mimic4.py b/pyhealth/datasets/mimic4.py index 9d1aa55d8..c5392fb1e 100644 --- a/pyhealth/datasets/mimic4.py +++ b/pyhealth/datasets/mimic4.py @@ -122,12 +122,14 @@ def __init__( "Events from discharge table only have date timestamp (no specific time). " "This may affect temporal ordering of events.", UserWarning, + stacklevel=2, ) if "discharge_detail" in tables: warnings.warn( "Events from discharge_detail table only have date timestamp (no specific time). " "This may affect temporal ordering of events.", UserWarning, + stacklevel=2, ) log_memory_usage(f"Before initializing {dataset_name}") super().__init__( diff --git a/pyhealth/models/concare.py b/pyhealth/models/concare.py index c642ee810..c4274a856 100644 --- a/pyhealth/models/concare.py +++ b/pyhealth/models/concare.py @@ -954,6 +954,7 @@ def __init__( "and sum-pooled per visit for memory efficiency. This reduces " "per-visit code representations to a single scalar.", UserWarning, + stacklevel=2, ) else: input_dim = proc.size() diff --git a/pyhealth/models/stagenet.py b/pyhealth/models/stagenet.py index 79900e134..11ad3fb73 100644 --- a/pyhealth/models/stagenet.py +++ b/pyhealth/models/stagenet.py @@ -440,6 +440,7 @@ def forward_from_embedding( f"StageNet format with time intervals for " f"better performance.", UserWarning, + stacklevel=2, ) else: time = time.to(self.device) @@ -453,6 +454,7 @@ def forward_from_embedding( f"Feature '{feature_key}' does not have mask " f"information. Default mask will be created from " f"embedded values. But it may not be accurate.", + stacklevel=2, ) mask = (value.abs().sum(dim=-1) != 0).int() elif not processor.is_token() and value.dim() == mask.dim(): diff --git a/pyhealth/models/stagenet_mha.py b/pyhealth/models/stagenet_mha.py index 637f2fdc5..5e3d5acef 100644 --- a/pyhealth/models/stagenet_mha.py +++ b/pyhealth/models/stagenet_mha.py @@ -516,6 +516,7 @@ def forward_from_embedding( f"StageNet format with time intervals for " f"better performance.", UserWarning, + stacklevel=2, ) else: time = time.to(self.device) @@ -528,6 +529,7 @@ def forward_from_embedding( f"Feature '{feature_key}' does not have mask " f"information. Default mask will be created from " f"embedded values. But it may not be accurate.", + stacklevel=2, ) mask = (value.abs().sum(dim=-1) != 0).int() elif not processor.is_token() and value.dim() == mask.dim(): diff --git a/pyhealth/models/text_embedding.py b/pyhealth/models/text_embedding.py index 57549fea5..15e388555 100644 --- a/pyhealth/models/text_embedding.py +++ b/pyhealth/models/text_embedding.py @@ -244,6 +244,7 @@ def _chunk_and_encode( f"Text produced {original_chunks} chunks, truncated to {self.max_chunks}. " f"Consider increasing max_chunks or summarizing input.", UserWarning, + stacklevel=2, ) # Step 4: Pad chunks to uniform length for batched encoding