generate_analysis_schema
This file defines the output schema for generating trajectories using zero-shot models.
Example Usage:
At the end of generate_trajectory script:
validated_df = validate_generated_data(df)
generation_analysis_schema()
Generate the schema for trajectory analysis data with consistent field ordering.
Returns:
| Type | Description |
|---|---|
|
pyarrow.Schema: The schema for trajectory analysis |
Source code in meds_torch/schemas/generate_analysis_schema.py
validate_generated_data(df)
Validate generated data against the schema and ensure correct ordering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
polars.DataFrame to validate |
required |
Returns:
| Type | Description |
|---|---|
|
pyarrow.Table: Validated data cast to the correct schema with ordered columns |
Example:
import polars as pl from datetime import datetime df = pl.DataFrame({ … ‘time’: [datetime(2024, 7, 18, 16, 21, 41)] * 3, … ‘code’: [‘A1’, ‘A2’, ‘A3’], … ‘code/vocab_index’: [55, 59, 61], … ‘numeric_value’: [0.625, 0.625, float(‘nan’)], … ‘subject_id’: [109767, 109767, 109767], … ‘prediction_time’: [datetime(2024, 7, 18, 16, 21, 41)] * 3, … ‘TRAJECTORY_TYPE’: [‘INPUT_DATA’] * 3 … }) validate_generated_data(df) pyarrow.Table subject_id: int64 prediction_time: timestamp[ns] time: timestamp[ns] code: string code/vocab_index: int64 numeric_value: double TRAJECTORY_TYPE: string
subject_id: [[109767,109767,109767]] prediction_time: [[2024-07-18 16:21:41.000000000,2024-07-18 16:21:41.000000000,2024-07-18 16:21:41.00…]] time: [[2024-07-18 16:21:41.000000000,2024-07-18 16:21:41.000000000,2024-07-18 16:21:41.000000000]] code: [[“A1”,”A2”,”A3”]] code/vocab_index: [[55,59,61]] numeric_value: [[0.625,0.625,nan]] TRAJECTORY_TYPE: [[“INPUT_DATA”,”INPUT_DATA”,”INPUT_DATA”]]