cdm_data_loaders.converters.facades.xsd_to_pyarrow ¶
Convert XML Schema Definition (XSD) documents into PyArrow schemas and empty tables.
XsdToPyArrowError ¶
Bases: ConversionError
Base class for XSD constructs that cannot be converted to a PyArrow schema.
Each subclass carries a stable specification code and a short title; its docstring states the reason
the construct is rejected. The converter specification document is generated from these attributes.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
XmlTagNotFoundError ¶
Bases: XsdToPyArrowError
The target element is not declared anywhere in the XSD.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
AmbiguousXmlTagError ¶
Bases: XsdToPyArrowError
Declarations of xml_tag at the shallowest matching depth have different types, so no single pa.Schema can be chosen.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
NonStructXmlTagError ¶
Bases: XsdToPyArrowError
A pa.Table schema needs top-level columns: the type of xml_tag must yield at least one attribute, #text, or child element field.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
WildcardElementError ¶
Bases: XsdToPyArrowError
Arbitrary undeclared child elements cannot be represented as fixed pa.struct fields.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
WildcardAttributeError ¶
Bases: XsdToPyArrowError
Arbitrary undeclared attributes cannot be represented as fixed pa.struct fields.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
AbstractComponentError ¶
Bases: XsdToPyArrowError
Concrete instances of an abstract element or type require xsi:type or substitution polymorphism, which has no single schema.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
SubstitutionGroupError ¶
Bases: XsdToPyArrowError
Substituted elements introduce element names and types that are not declared in the parent content model.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
FieldNameCollisionError ¶
Bases: XsdToPyArrowError
An attribute (prefixed _) and a child element map to the same field name in one pa.struct.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
RecursiveNonJsonTypeError ¶
Bases: XsdToPyArrowError
Subtrees truncated beyond max_recursion_depth are serialized with json.dumps, which cannot encode datetime.date or bytes without lossy conversion.
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
XsdToPyArrow
pydantic-model
¶
Bases: BaseModel
Facade converting XML Schema Definition (XSD) documents into PyArrow schemas and empty tables.
Show JSON schema:
{
"description": "Facade converting XML Schema Definition (XSD) documents into PyArrow schemas and empty tables.",
"properties": {
"xml_tag": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Xml Tag"
},
"max_recursion_depth": {
"default": 2,
"exclusiveMinimum": 0,
"title": "Max Recursion Depth",
"type": "integer"
}
},
"title": "XsdToPyArrow",
"type": "object"
}
Config:
arbitrary_types_allowed:Truefrozen:True
Fields:
-
xml_tag(str | None) -
max_recursion_depth(PositiveInt)
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
convert ¶
Convert an XSD schema element into a pa.Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema | str | Path
|
loaded |
required |
xml_tag
|
str | None
|
target XML element name (defaults to |
None
|
Returns:
| Type | Description |
|---|---|
pa.Schema
|
converted PyArrow schema |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
convert_to_table ¶
Convert an XSD schema element into a zero-row pa.Table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema | str | Path
|
loaded |
required |
xml_tag
|
str | None
|
target XML element name (defaults to |
None
|
Returns:
| Type | Description |
|---|---|
pa.Table
|
zero-row PyArrow table with the converted schema |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
convert_to_python ¶
convert_to_python(
schema: XMLSchema | str | Path,
xml_tag: str | None = None,
*,
docstring: str | None = None
) -> str
Convert an XSD schema element into a static Python schema module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema | str | Path
|
loaded |
required |
xml_tag
|
str | None
|
target XML element name (defaults to |
None
|
docstring
|
str | None
|
optional module docstring header |
None
|
Returns:
| Type | Description |
|---|---|
str
|
formatted Python source code defining |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
convert_to_python_file ¶
convert_to_python_file(
schema: XMLSchema | str | Path,
output: str | Path,
xml_tag: str | None = None,
*,
docstring: str | None = None
) -> Path
Convert an XSD schema element and write a static Python schema module to output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema | str | Path
|
loaded |
required |
output
|
str | Path
|
destination file path for the generated Python module |
required |
xml_tag
|
str | None
|
target XML element name (defaults to |
None
|
docstring
|
str | None
|
optional module docstring header |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
resolved output |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
convert_level_to_python ¶
convert_level_to_python(
schema: XMLSchema | str | Path,
level: int = 1,
*,
root_tag: str | None = None,
docstring: str | None = None
) -> str
Convert all XML element types at depth level in an XSD schema into a static Python schema module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema | str | Path
|
loaded |
required |
level
|
int
|
non-negative depth relative to the root element(s) |
1
|
root_tag
|
str | None
|
optional explicit root element name to anchor the traversal |
None
|
docstring
|
str | None
|
optional module docstring header |
None
|
Returns:
| Type | Description |
|---|---|
str
|
formatted Python source code defining |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
convert_level_to_python_file ¶
convert_level_to_python_file(
schema: XMLSchema | str | Path,
output: str | Path,
level: int = 1,
*,
root_tag: str | None = None,
docstring: str | None = None
) -> Path
Convert all XML element types at depth level in an XSD schema and write a Python module to output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema | str | Path
|
loaded |
required |
output
|
str | Path
|
destination file path for the generated Python module |
required |
level
|
int
|
non-negative depth relative to the root element(s) |
1
|
root_tag
|
str | None
|
optional explicit root element name to anchor the traversal |
None
|
docstring
|
str | None
|
optional module docstring header |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
resolved output |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
resolve_scalar_type ¶
Map a non-list XSD simpleType (atomic or union) to (pa.DataType, xsd_type_str).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simple_type
|
XsdType
|
XSD simpleType to resolve. |
required |
Returns:
| Type | Description |
|---|---|
tuple[pa.DataType, str]
|
Tuple of |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
generate_pyarrow_struct ¶
generate_pyarrow_struct(
schema: XMLSchema,
xml_tag: str,
*,
max_recursion_depth: int = DEFAULT_MAX_RECURSION_DEPTH,
struct_cache: dict[tuple[int, bool], Any] | None = None
) -> pa.StructType
Generate a reusable pa.StructType component for the target XML element from an XSD schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema
|
loaded XMLSchema instance |
required |
xml_tag
|
str
|
target XML element name (local name or Clark-notation |
required |
max_recursion_depth
|
int
|
maximum structural recursion depth before JSON serialization |
DEFAULT_MAX_RECURSION_DEPTH
|
struct_cache
|
dict[tuple[int, bool], Any] | None
|
optional cache for sharing complex type components across calls |
None
|
Returns:
| Type | Description |
|---|---|
pa.StructType
|
PyArrow StructType component whose fields correspond to the target element's fields |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
generate_pyarrow_schema ¶
generate_pyarrow_schema(
schema: XMLSchema,
xml_tag: str,
*,
max_recursion_depth: int = DEFAULT_MAX_RECURSION_DEPTH
) -> pa.Schema
Generate a PyArrow schema for the target XML element from an XSD schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema
|
loaded XMLSchema instance |
required |
xml_tag
|
str
|
target XML element name (local name or Clark-notation |
required |
max_recursion_depth
|
int
|
maximum structural recursion depth before JSON serialization |
DEFAULT_MAX_RECURSION_DEPTH
|
Returns:
| Type | Description |
|---|---|
pa.Schema
|
PyArrow schema whose top-level fields correspond to the target element's fields |
Source code in src/cdm_data_loaders/converters/facades/xsd_to_pyarrow.py
generate_pyarrow_schemas_at_level ¶
generate_pyarrow_schemas_at_level(
schema: XMLSchema,
level: int,
*,
root_tag: str | None = None,
max_recursion_depth: int = DEFAULT_MAX_RECURSION_DEPTH
) -> dict[str, pa.Schema]
Generate PyArrow table schemas for all XML element types at depth level in an XSD schema.
Reusable struct components are cached and shared across all table schemas assembled
at level. Elements whose XSD type resolves to a scalar or mixed-text leaf are represented as
a single-column pa.Schema with a nullable #text field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
XMLSchema
|
loaded XMLSchema instance |
required |
level
|
int
|
non-negative depth relative to the root element(s) |
required |
root_tag
|
str | None
|
optional explicit root element name to anchor the traversal |
None
|
max_recursion_depth
|
int
|
maximum structural recursion depth before JSON serialization |
DEFAULT_MAX_RECURSION_DEPTH
|
Returns:
| Type | Description |
|---|---|
dict[str, pa.Schema]
|
mapping of element local tag name (table name) to its assembled PyArrow schema |