cdm_data_loaders.coercion.pyarrow ¶
Coerce JSON-parsed records and scalar values to match a target PyArrow schema.
pyarrow_to_python_type_label ¶
Return the Markdown-formatted Python runtime type label corresponding to a coerced PyArrow DataType.
Mirrors the scalar and list coercion rules enforced by :func:coerce_record_for_pyarrow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_type
|
DataType
|
Target PyArrow data type. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Backtick-wrapped Python runtime type label (e.g. |
Source code in src/cdm_data_loaders/coercion/pyarrow.py
coerce_record_for_pyarrow ¶
Coerce a JSON-validated record dictionary to match a PyArrow schema.
Only fields declared in schema are retained and coerced recursively so
pyarrow.Table.from_pylist can construct a table matching schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
dict[str, Any]
|
JSON-parsed and schema-validated record dictionary. |
required |
schema
|
Schema
|
Target PyArrow schema for the record's table. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Coerced record dictionary ready for |
Source code in src/cdm_data_loaders/coercion/pyarrow.py
serialize_table_for_jsonschema ¶
Serialize a pa.Table into JSON-compatible row dictionaries matching generate_json_schema.
Encodes Decimal values as plain fixed-point strings, binary columns as ASCII Base64 strings,
temporal columns as ISO-8601 strings, and pa.map_ columns as [{"key": ..., "value": ...}] arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
Input PyArrow table. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of JSON-compatible row dictionaries ready for JSON Schema validation. |
Source code in src/cdm_data_loaders/coercion/pyarrow.py
serialize_record_for_jsonschema ¶
Serialize a single Python row mapping matching schema for JSON Schema validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
Mapping[str, Any]
|
Input Python row dictionary matching |
required |
schema
|
Schema
|
PyArrow schema describing |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
JSON-compatible dictionary matching |
Source code in src/cdm_data_loaders/coercion/pyarrow.py
serialize_table_for_linkml ¶
Serialize a pa.Table into JSON-compatible row dictionaries matching generate_linkml_schema.
Encodes Decimal values as plain fixed-point strings, binary columns as ASCII Base64 strings,
temporal columns as ISO-8601 strings, and pa.map_ columns as [{"key": ..., "value": ...}] entry
lists while rejecting null list items and nested multivalued list/map items unsupported by LinkML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
Input PyArrow table. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of JSON-compatible row dictionaries ready for LinkML validation. |
Source code in src/cdm_data_loaders/coercion/pyarrow.py
serialize_record_for_linkml ¶
Serialize a single Python row mapping matching schema for LinkML validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
Mapping[str, Any]
|
Input Python row dictionary matching |
required |
schema
|
Schema
|
PyArrow schema describing |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
JSON-compatible dictionary matching |