Repository navigation
Make removed 1.x classes fail at once with the 2.x replacement #1451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """PyHealth 1.x classes fail at once with a pointer to the 2.x API. | ||
|
|
||
| They used to be stubs whose ``__init__`` only warned, so a subclass built | ||
| an object with none of its attributes set and failed much later (#1201). | ||
| """ | ||
|
|
||
| import unittest | ||
|
|
||
| from pyhealth.data import Visit | ||
| from pyhealth.datasets import ( | ||
| BaseEHRDataset, | ||
| BaseSignalDataset, | ||
| SampleEHRDataset, | ||
| SampleSignalDataset, | ||
| ) | ||
|
|
||
| REMOVED = { | ||
| BaseEHRDataset: "BaseDataset", | ||
| BaseSignalDataset: "BaseDataset", | ||
| SampleEHRDataset: "SampleDataset", | ||
| SampleSignalDataset: "SampleDataset", | ||
| Visit: "Patient.get_events", | ||
| } | ||
|
|
||
|
|
||
| class TestRemoved1xClasses(unittest.TestCase): | ||
| def test_instantiating_raises_with_replacement(self): | ||
| for cls, replacement in REMOVED.items(): | ||
| with self.subTest(cls=cls.__name__): | ||
| with self.assertRaises(NotImplementedError) as ctx: | ||
| cls(root="data", tables=["DIAGNOSES_ICD"]) | ||
| message = str(ctx.exception) | ||
| self.assertIn(f"{cls.__name__} was removed in PyHealth 2.0", message) | ||
| self.assertIn(replacement, message) | ||
|
|
||
| def test_subclass_raises_too(self): | ||
| for cls in REMOVED: | ||
| with self.subTest(cls=cls.__name__): | ||
| subclass = type("Legacy" + cls.__name__, (cls,), {}) | ||
| with self.assertRaises(NotImplementedError): | ||
| subclass() | ||
|
|
||
| def test_in_tree_legacy_datasets_name_themselves(self): | ||
| from pyhealth.datasets import ( | ||
| CardiologyDataset, | ||
| ISRUCDataset, | ||
| MIMICExtractDataset, | ||
| SHHSDataset, | ||
| ) | ||
|
|
||
| for cls in (CardiologyDataset, ISRUCDataset, SHHSDataset): | ||
| with self.subTest(cls=cls.__name__): | ||
| with self.assertRaises(NotImplementedError) as ctx: | ||
| cls(root="data") | ||
| message = str(ctx.exception) | ||
| self.assertIn(f"{cls.__name__} is built on", message) | ||
| self.assertIn("does not work yet", message) | ||
| with self.assertRaises(NotImplementedError) as ctx: | ||
| MIMICExtractDataset(root="data", tables=["C"]) | ||
| self.assertIn( | ||
| "MIMICExtractDataset is built on BaseEHRDataset", str(ctx.exception) | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[medium] In-tree dataset subclasses of the removed stubs now raise a misleading error
The PR says nothing in pyhealth/ uses these classes, but this is not true. CardiologyDataset (cardiology.py:11, calls super().init at :50), ISRUCDataset (isruc.py:76, inherits init) and SHHSDataset (shhs.py:8) subclass BaseSignalDataset. MIMICExtractDataset (mimicextract.py:12, super().init at :141) subclasses BaseEHRDataset. All four are exported from pyhealth/datasets/init.py, and ISRUCDataset is constructed in code in pyhealth/calib/calibration/hb.py:248 and dircal.py:213. The stub never set the attributes these classes use (root, dev, kwargs, filepath), so they could not work before either. With this change, constructing them raises 'BaseSignalDataset was removed in PyHealth 2.0. Use BaseDataset ...', which names the wrong cause for a 2.x class. Fix: port these four datasets onto BaseDataset/SampleDataset in this PR, or state in the description that they are known to be unusable, correct the 'nothing uses them' claim, and cover the calib call sites. No test exercises these classes.