Skip to content

Transform

Use @transform on a function before adding it to a pipeline. The decorated function also validates its inputs and output when called directly.

Use @side_effect or @transform(side_effect=True) for a final step that writes or prints data. It must declare -> None. Pass include_side_effects=False to Pipeline.run() to skip these steps while running the rest of the pipeline.

data_joinery.transform.transform

transform(
    f: Callable[P, R], *, side_effect: bool = False
) -> Transform[P, R]
transform(
    f: None = None, *, side_effect: bool = False
) -> Callable[[Callable[P, R]], Transform[P, R]]
transform(f=None, *, side_effect=False)

Decorate a function to validate its annotated inputs and output.

Use as @transform, @transform(), or @transform(side_effect=True). A side-effect transform must explicitly return None and can be skipped by Pipeline.run. DataFrame contracts in Annotated control schema validation and coercion. Other supported runtime classes are checked with isinstance.

PARAMETER DESCRIPTION
f

Function to decorate. Omit when using @transform().

TYPE: Callable[P, R] | None DEFAULT: None

side_effect

Mark a terminal transform that can be skipped by a pipeline run.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Transform[P, R] | Callable[[Callable[P, R]], Transform[P, R]]

A callable transform that can also be added to a pipeline.

Source code in src/data_joinery/transform.py
def transform[**P, R](
    f: Callable[P, R] | None = None,
    *,
    side_effect: bool = False,
) -> Transform[P, R] | Callable[[Callable[P, R]], Transform[P, R]]:
    """Decorate a function to validate its annotated inputs and output.

    Use as ``@transform``, ``@transform()``, or
    ``@transform(side_effect=True)``. A side-effect transform must explicitly
    return ``None`` and can be skipped by ``Pipeline.run``. DataFrame contracts in
    ``Annotated`` control schema validation and coercion. Other supported
    runtime classes are checked with ``isinstance``.

    Args:
        f: Function to decorate. Omit when using ``@transform()``.
        side_effect: Mark a terminal transform that can be skipped by a pipeline run.

    Returns:
        A callable transform that can also be added to a pipeline.
    """
    if f is None:
        return lambda fn: Transform(fn, side_effect=side_effect)

    return Transform(f, side_effect=side_effect)

data_joinery.transform.side_effect

side_effect(f)

Mark a terminal transform as a side effect.

This is shorthand for @transform(side_effect=True). The function must explicitly declare -> None. Calling it directly still runs it.

Source code in src/data_joinery/transform.py
def side_effect[**P, R](f: Callable[P, R]) -> Transform[P, R]:
    """Mark a terminal transform as a side effect.

    This is shorthand for ``@transform(side_effect=True)``. The function must
    explicitly declare ``-> None``. Calling it directly still runs it.
    """
    return Transform(f, side_effect=True)