Skip to main content

Builds sample MEDS datasets for testing.

Project description

MEDS Testing Helpers

python tests codecov code-quality license PRs contributors

Provides various utilities for testing and benchmarking MEDS packages and tools, including pytest helpers, fixtures, sample datasets, and capabilities to build larger sample datasets for benchmarking purposes.

Installation

pip install meds_testing_helpers

Testing Helpers

After installing this package via pip, you can use the provided pytest fixtures and helpers to test your MEDS pipelines and tools. These include fixtures for static datasets shipped with this package and fixtures that generate larger datasets on the fly for benchmarking purposes.

Simple Static Dataset

You can use the fixture simple_static_MEDS to access a simple, static dataset that is sharded by split (e.g., shard names are of the form train/0.parquet. To use this fixture, simply add it as an argument to your test function in pytest:

# test_my_pipeline.py


def test_my_pipeline(simple_static_MEDS):
    # The simple static dataset will be stored on disk in a temporary directory in a path given by
    # the `simple_static_MEDS` input variable.
    pass

Note that you can also import this static dataset directly in yaml form then convert it to a MEDS dataset in a simple object-oriented format that can be written to disk via:

from meds_testing_helpers.static_sample_data import SIMPLE_STATIC_SHARDED_BY_SPLIT
from meds_testing_helpers.dataset import MEDSDataset

data = MEDSDataset.from_yaml(SIMPLE_STATIC_SHARDED_BY_SPLIT)
data.write(...)

Generated Datasets (useful for benchmarking)

You can use the fixture generated_sample_MEDS to generate a sample dataset that is similar to the static dataset discussed above dynamically with a controllable number of patients (controlled via the pytest argument --generated-dataset-N). This dataset is generated on the fly and is not stored on disk, so will take some time to generate depending on the number of patients. The dataset is generated according to the relevant configuration file. Over time, more configs and data generation specifications will be added. Like the static datasets, as a pytest fixture this can be accessed via a temporary path:

# test_my_pipeline.py


def test_my_pipeline(generated_sample_MEDS):
    # The generated dataset will be stored on disk in a temporary directory in a path given by
    # the `generated_sample_MEDS` input variable.
    pass

You can also control the seed of the generation process via the pytest argument --generated-dataset-seed.

Building Sample Datasets

This package also contains an executable to generate sample MEDS datasets and store them to disk. It is this command that backs the generated_sample_MEDS pytest fixtures. This CLI tool uses hydra to manage configuration options and generate datasets according to the configuration. You can run the command as follows:

build_sample_MEDS_dataset dataset_spec=sample N_subjects=500

Add do_overwrite=True to overwrite an existing dataset. You can see the full configuration options by running sample_MEDS --help.

Inferring Dataset Generation Configs

To generate a dataset similar to a local dataset on disk, you can also use the infer_MEDS_sample_gen_config CLI command to infer the dataset generation configuration from a local dataset. This command will output a yaml file to a specified path on disk that can be used as input to the build_sample_MEDS_dataset command to generate a dataset similar to the local dataset along some limited axes. There is not a clean way currently to use the yaml file on disk other than making a new dataset_spec configuration file and referencing that directly via Hydra.

infer_MEDS_sample_gen_config dataset_dir=/path/to/local/dataset output_fp=/path/to/output.yaml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meds_testing_helpers-0.2.1.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

meds_testing_helpers-0.2.1-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file meds_testing_helpers-0.2.1.tar.gz.

File metadata

  • Download URL: meds_testing_helpers-0.2.1.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for meds_testing_helpers-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bcaceb78a0e9537552e4dd936fea920002e8989b523e22ce1f0a36a5e286fd1d
MD5 37b64d751528875998728e0e5ccf5027
BLAKE2b-256 b535a4d23fd5469b0924b521c137f1b8bab10a22613fd9f875a2494dec39f067

See more details on using hashes here.

Provenance

The following attestation bundles were made for meds_testing_helpers-0.2.1.tar.gz:

Publisher: python-build.yaml on Medical-Event-Data-Standard/meds_testing_helpers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file meds_testing_helpers-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for meds_testing_helpers-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0434dfda03bd284eb31dc8f38d2a4c4241e629710e9e222c3a3bb806b36c311b
MD5 608b73970481112e25de4e6874b17df8
BLAKE2b-256 1ca79d0cf9289727adf038a782c8509e9bdcbec8fc2461b9b88920d516f5ace7

See more details on using hashes here.

Provenance

The following attestation bundles were made for meds_testing_helpers-0.2.1-py3-none-any.whl:

Publisher: python-build.yaml on Medical-Event-Data-Standard/meds_testing_helpers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page