Value checks with pandera on cohort files, read and written, and on estimates, written and stored

This commit is contained in:
2026-11-06 00:44:58 -06:00
parent 71e77f0c7e
commit 5d65730b98
7 changed files with 127 additions and 17 deletions
+3 -3
View File
@@ -19,8 +19,8 @@ import pyarrow as pa
import pyarrow.parquet as pq
from sqlalchemy.engine import make_url
from models.io.contracts import (COHORT_SCHEMA, EXCLUSION, INDEX, POPULATION, CohortDefinitionError, CohortFileError,
CohortQueries, ExclusionRule)
from models.io.contracts import (COHORT_FRAME, COHORT_SCHEMA, EXCLUSION, INDEX, POPULATION, CohortDefinitionError,
CohortFileError, CohortQueries, ExclusionRule, check_frame)
def cohorts_root(database_url: str) -> Path:
@@ -108,7 +108,7 @@ def read_cohort(path: str | Path) -> pd.DataFrame:
schema = pq.read_schema(path)
if not schema.equals(COHORT_SCHEMA, check_metadata=False):
raise CohortFileError(f"{path} doesn't have a cohort build's columns: {schema.names}")
return pd.read_parquet(path)
return check_frame(COHORT_FRAME, pd.read_parquet(path), CohortFileError, str(path))
def write_once(table: pa.Table, path: Path) -> None: