Value checks with pandera on cohort files, read and written, and on estimates, written and stored
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user