Skip to content

yggdrasil.exceptions.cast

cast

Cast-related exception types.

Lives under :mod:yggdrasil.exceptions so any module can import these without pulling :mod:yggdrasil.data or :mod:yggdrasil.arrow first — exceptions are reachable from the hot path without ordering surprises.

CastError

CastError(
    reason: str,
    *,
    source: "Field | None" = None,
    target: "Field | None" = None,
    original: BaseException | None = None
)

Bases: YGGException, ArrowInvalid

Raised when casting a value / array / table to a target field fails.

Carries the source and target :class:Field so the message can name which column was being cast — without these, debugging a multi-column write meant guessing which child raised. Subclassing :class:pyarrow.ArrowInvalid keeps every existing except pa.ArrowInvalid handler in the wider codebase catching these unchanged; subclassing :class:YGGException lets a generic except YGGException catch every error this library raises.

Message shape (single line so logs stay readable):

::

cast payload: string -> payload: list<struct<a:int64, b:string>> failed:
Invalid JSON at row 0: ... Value: 'pypsa'.

original preserves the underlying exception for raise ... from chains and for callers that want the raw pyarrow / json failure object.