Repository navigation
Warn about the default dataset cache; allow requiring cache_dir - #1264
Merged
Merged
Conversation
Without cache_dir, a dataset writes processed copies of its source data (the event table and task samples) to the user cache folder, e.g. ~/Library/Caches/pyhealth, and said so only at INFO level. For identified clinical data that silently copies row-level data outside the project's controlled storage. - New _default_cache_dir() (base_dataset): logs a WARNING naming the path, once per path; raises ValueError if PYHEALTH_REQUIRE_CACHE_DIR is 1/true/yes, before anything is written. Used by BaseDataset and by the FHIR dataset base, which had its own copy of the default. - tests/core/test_default_cache_dir.py: warning names the path and the env var, warns once, no warning with an explicit cache_dir, the env var raises without creating anything and allows an explicit cache_dir. - docs/api/datasets.rst: default location and a "Working with identified data" section. - examples/require_cache_dir.py on the bundled MIMIC-III demo. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 tasks done
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When no
cache_diris given, a dataset writes processed copies of its source data (the event table every patient is read from, and the samples eachset_task()produces) to the user cache folder:platformdirs.user_cache_dir("pyhealth"), e.g.~/Library/Caches/pyhealthor~/.cache/pyhealth. That was logged only at INFO level.For identified clinical data this silently copies row-level data outside the project's controlled storage. A downstream EHR project found it only by reading the code.
Changes
cache_dir, PyHealth logs a WARNING naming the resolved path and explaining what is written there. It warns once per path, so repeated loads don't spam.PYHEALTH_REQUIRE_CACHE_DIR=1(ortrue/yes), a dataset created withoutcache_dirraisesValueErrorbefore writing anything. An environment variable protects every script and notebook in a project at once, which a per-call argument can't._default_cache_dir(), is used byBaseDatasetand by the FHIR dataset base, which had its own copy of the default.MEDSDatasetinherits it.cache_diris given, and the default location itself.Tests, docs, example
tests/core/test_default_cache_dir.py:cache_dirgives no warning;cache_dir.docs/api/datasets.rst: thecache_dirbullet names the default location, and there is a new "Working with identified data" section. That section also notes thatcreate_sample_dataset(..., in_memory=False)writes to the system temp folder.examples/require_cache_dir.pyon the bundled MIMIC-III demo.Ran 1386 tests … OK (skipped=76).tools/check_pr_rules.pypasses.🤖 Generated with Claude Code