yera.apps.typing.coerce

Type coercion: converting values to declared types at app call time.

Symbols

def coerce_bool — Coerce to bool with proper string handling.
def coerce_dataframe — Coerce to pandas DataFrame.
def coerce_date — Coerce to date.
def coerce_datetime — Coerce to datetime.
def coerce_decimal — Coerce to Decimal.
def coerce_dict — Coerce to dict[K, V] type.
def coerce_enum — Coerce to Enum type.
def coerce_fallback — Fallback coercion - just check isinstance.
def coerce_float — Coerce to float with proper string handling.
def coerce_int — Coerce to int with proper string handling.
def coerce_list — Coerce to list[T] type.
def coerce_literal — Coerce to Literal type.
def coerce_none — Coerce to None type.
def coerce_set — Coerce a value to a ``set[T]``.
def coerce_str — Coerce to str with proper string handling.
def coerce_struct — Coerce to Struct (Pydantic model) type.
def coerce_time — Coerce to time.
def coerce_timedelta — Coerce to timedelta.
def coerce_union — Coerce to Union type by trying each type in order.
def coerce_value — Coerce a value to the expected type.
def is_generic — Return whether ``t`` is a parameterised generic origin (``list``, ``dict``, ``set``, ``Literal``, ``Union``).
def serialise_dataframe — Serialize DataFrame to Parquet bytes.

coerce_bool

coerce_bool(
    value: Any,
) → bool

Coerce to bool with proper string handling.

coerce_dataframe

coerce_dataframe(
    value: Any,
) → pd.DataFrame

Coerce to pandas DataFrame.

coerce_date

coerce_date(
    value: Any,
) → date

Coerce to date.

coerce_datetime

coerce_datetime(
    value: Any,
) → datetime

Coerce to datetime.

coerce_decimal

coerce_decimal(
    value: Any,
) → Decimal

Coerce to Decimal.

coerce_dict

coerce_dict(
    value: Any,
    expected_type: Any,
) → dict

Coerce to dict[K, V] type.

coerce_enum

coerce_enum(
    value: Any,
    expected_type: type[Enum],
) → Enum

Coerce to Enum type.

coerce_fallback

coerce_fallback(
    value: Any,
    expected_type: Any,
) → Any

Fallback coercion - just check isinstance.

coerce_float

coerce_float(
    value: Any,
) → float

Coerce to float with proper string handling.

coerce_int

coerce_int(
    value: Any,
) → int

Coerce to int with proper string handling.

coerce_list

coerce_list(
    value: Any,
    expected_type: Any,
) → list

Coerce to list[T] type.

coerce_literal

coerce_literal(
    value: Any,
    expected_type: Any,
) → Any

Coerce to Literal type.

coerce_none

coerce_none(
    value: Any,
) → None

Coerce to None type.

coerce_set

coerce_set(
    value: Any,
    expected_type: Any,
) → set

Coerce a value to a set[T].

Accepts a set, list, or JSON-encoded string.

coerce_str

coerce_str(
    value: Any,
) → str

Coerce to str with proper string handling.

coerce_struct

coerce_struct(
    value: Any,
    expected_type: type[Struct],
) → Any

Coerce to Struct (Pydantic model) type.

coerce_time

coerce_time(
    value: Any,
) → time

Coerce to time.

coerce_timedelta

coerce_timedelta(
    value: Any,
) → timedelta

Coerce to timedelta.

coerce_union

coerce_union(
    value: Any,
    expected_type: Any,
) → Any

Coerce to Union type by trying each type in order.

coerce_value

coerce_value(
    value: Any,
    expected_type: Any,
) → Any

Coerce a value to the expected type.

Delegates to specialized handlers based on type structure.

is_generic

is_generic(
    t: type,
) → bool

Return whether t is a parameterised generic origin (list, dict, set, Literal, Union).

serialise_dataframe

serialise_dataframe(
    df: pd.DataFrame,
) → bytes

Serialize DataFrame to Parquet bytes.