cdm_data_loaders.converters.facades.pyarrow_to_linkml ¶
Convert PyArrow schemas, fields, and data types to official LinkML schema definitions.
PyArrowToLinkMLError ¶
Bases: ConversionError
Raised when a PyArrow schema, field, or data type cannot be converted to a LinkML schema.
Subclasses raised by :func:generate_linkml_schema carry a stable specification code and a short
title; their docstrings state why the construct is rejected. The converter specification document is
generated from these attributes.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
InvalidPyArrowSchemaError ¶
Bases: PyArrowToLinkMLError
Schema generation requires a concrete PyArrow pa.Schema object; bare pa.DataType, pa.Field, or Python mappings are not table schemas.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
EmptyStructError ¶
Bases: PyArrowToLinkMLError
Arrow tables and LinkML record classes generated from Arrow structs require at least one named attribute.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
DuplicateFieldNameError ¶
Bases: PyArrowToLinkMLError
LinkML class attributes is keyed by slot name and cannot represent duplicate sibling field names.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
NullOnlyTypeError ¶
Bases: PyArrowToLinkMLError
A column or container element typed solely as pa.null() carries no value domain; nullable columns must wrap a concrete Arrow value type with nullable=True.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
InvalidDecimalTypeError ¶
Bases: PyArrowToLinkMLError
Fixed-point decimal representations require 0 <= scale <= precision; negative scales or scale > precision have no plain decimal slot representation.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
UnsupportedTemporalIntervalError ¶
Bases: PyArrowToLinkMLError
Relative durations and month_day_nano intervals have no lossless built-in linkml:types scalar range.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
UnsupportedUnionTypeError ¶
Bases: PyArrowToLinkMLError
Arrow type-code unions cannot be represented as typed LinkML slots without class/union redesign.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
UnsupportedArrowTypeError ¶
Bases: PyArrowToLinkMLError
Specialized physical encodings such as pa.run_end_encoded and custom pa.ExtensionType subclasses have no general LinkML mapping.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
EmptyFieldNameError ¶
Bases: PyArrowToLinkMLError
LinkML SlotDefinition identifiers require a non-empty attribute name; blank Arrow field names cannot form valid LinkML slots.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
NestedMultivaluedSlotError ¶
Bases: PyArrowToLinkMLError
LinkML slots use a flat multivalued: true flag on a single range and cannot represent multidimensional lists or lists of map-entry lists without intermediate wrapper classes.
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
PyArrowToLinkML
pydantic-model
¶
Bases: BaseModel
Frozen facade converting PyArrow pa.Schema objects to LinkML SchemaDefinition models and YAML.
Show JSON schema:
{
"description": "Frozen facade converting PyArrow ``pa.Schema`` objects to LinkML ``SchemaDefinition`` models and YAML.",
"properties": {
"schema_name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Schema Name"
},
"schema_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Schema Id"
}
},
"title": "PyArrowToLinkML",
"type": "object"
}
Config:
arbitrary_types_allowed:Truefrozen:True
Fields:
-
schema_name(str | None) -
schema_id(str | None)
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
convert ¶
Convert a PyArrow pa.Schema into a LinkML SchemaDefinition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow schema. |
required |
Returns:
| Type | Description |
|---|---|
SchemaDefinition
|
Emitted LinkML |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
convert_to_yaml ¶
Convert a PyArrow pa.Schema into a LinkML YAML string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow schema. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Serialized LinkML YAML string. |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
convert_to_yaml_file ¶
Convert a PyArrow pa.Schema and write the LinkML YAML schema to output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow schema. |
required |
output
|
str | Path
|
Destination YAML file path. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Resolved output |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
convert_type ¶
Convert a standalone PyArrow DataType into a LinkML SlotDefinition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
DataType
|
PyArrow data type to convert. |
required |
Returns:
| Type | Description |
|---|---|
SlotDefinition
|
Emitted LinkML |
Raises:
| Type | Description |
|---|---|
PyArrowToLinkMLError
|
If |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
resolve_scalar_type ¶
Resolve a scalar (or dictionary-encoded scalar) PyArrow DataType to its LinkML SlotDefinition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
DataType
|
Scalar PyArrow data type. |
required |
Returns:
| Type | Description |
|---|---|
SlotDefinition
|
Emitted LinkML |
Raises:
| Type | Description |
|---|---|
PyArrowToLinkMLError
|
If |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
convert_field ¶
Convert a PyArrow Field into a LinkML SlotDefinition with cardinality and description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pa_field
|
Field
|
PyArrow field to convert. |
required |
Returns:
| Type | Description |
|---|---|
SlotDefinition
|
Named LinkML |
Raises:
| Type | Description |
|---|---|
PyArrowToLinkMLError
|
If |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
generate_linkml_schema ¶
generate_linkml_schema(
schema: Schema,
*,
schema_name: str | None = None,
schema_id: str | None = None,
destination: SchemaDefinition | None = None
) -> SchemaDefinition
Generate an official LinkML SchemaDefinition from a PyArrow pa.Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow table schema. |
required |
schema_name
|
str | None
|
Optional LinkML schema and root class name (defaults to |
None
|
schema_id
|
str | None
|
Optional LinkML schema |
None
|
destination
|
SchemaDefinition | None
|
Optional existing |
None
|
Returns:
| Type | Description |
|---|---|
SchemaDefinition
|
Emitted LinkML |
Raises:
| Type | Description |
|---|---|
PyArrowToLinkMLError
|
If |
Source code in src/cdm_data_loaders/converters/facades/pyarrow_to_linkml.py
generate_linkml_yaml ¶
generate_linkml_yaml(
schema: Schema,
*,
schema_name: str | None = None,
schema_id: str | None = None
) -> str
Generate a LinkML YAML schema string from a PyArrow pa.Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Input PyArrow table schema. |
required |
schema_name
|
str | None
|
Optional LinkML schema and root class name. |
None
|
schema_id
|
str | None
|
Optional LinkML schema |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Serialized LinkML YAML string. |