Load the policy records
Each row of data/records.csv describes one policy, including identifying details and coverage amount. read_csv(...) reads the file, and Record.new(...) defines a separate Record instance from each row’s required fields (see Define base facts). In this loader, model.data(...).to_schema() omits a row if any field passed to Record.new(...) is empty, so including optional identifiers in that call could leave a whole policy out of the model. The optional-fields loop adds email, phone, and other identifiers separately, only for records that have those values.
def load_records() -> DataFrame: """Read policyholder records and load their base facts.""" records = read_csv( DATA_DIR / "records.csv", dtype={"postal_code": str, "gov_id_last4": str}, ).fillna("") records["coverage_amount"] = records["coverage_amount"].astype(float) model.define(Record.new(model.data(records[REQUIRED_COLS]).to_schema()))
for column in OPTIONAL_COLS: present = records[records[column] != ""][["record_id", column]] present_data = model.data(present) model.define( getattr(Record.lookup(record_id=present_data.record_id), column)( getattr(present_data, column) ) ) return recordsdef load_records() -> DataFrame: """Read policyholder records and load their base facts.""" records = read_csv( DATA_DIR / "records.csv", dtype={"postal_code": str, "gov_id_last4": str}, ).fillna("") records["coverage_amount"] = records["coverage_amount"].astype(float) model.define(Record.new(model.data(records[REQUIRED_COLS]).to_schema()))
for column in OPTIONAL_COLS: present = records[records[column] != ""][["record_id", column]] present_data = model.data(present) model.define( getattr(Record.lookup(record_id=present_data.record_id), column)( getattr(present_data, column) ) ) return records