pathwaycom/pathway · error · TypeError

Value {val} is not of type {dtype}.

Error message

Value {val} is not of type {dtype}.

What it means

During graph evaluation Pathway wraps an expression in a checking UDF that asserts every produced value satisfies dtype.is_value_compatible. If a row's actual value violates the declared dtype (e.g. a None in a non-Optional column, a str in an int column), the UDF raises this TypeError naming the offending value and dtype. It surfaces data/schema mismatches that static dtype checking could not catch.

Source

Thrown at python/pathway/internals/graph_runner/expression_evaluator.py:205

    def eval_expression(  # type: ignore[override]
        self, expression: expr.ColumnExpression, **kwargs
    ) -> expr.ColumnExpression:
        expression = super().eval_expression(expression, **kwargs)

        from pathway.internals.operator import RowTransformerOperator

        if isinstance(expression, expr.ColumnReference):
            if isinstance(
                expression._column.lineage.source.operator, RowTransformerOperator
            ):
                return expression

        dtype = expression._dtype

        @udf(return_type=dtype, deterministic=True)
        def test_type(val):
            if not dtype.is_value_compatible(val):
                raise TypeError(f"Value {val} is not of type {dtype}.")
            return val

        ret = test_type(expression)
        assert isinstance(ret, expr.ApplyExpression)
        ret._check_for_disallowed_types = False
        ret._dtype = dtype

        return ret


class RowwiseEvaluator(
    ExpressionEvaluator, ExpressionVisitor, context_type=clmn.RowwiseContext
):
    def run(
        self,
        output_storage: Storage,
        old_path: ColumnPath | None = ColumnPath.EMPTY,
        disable_runtime_typechecking: bool = False,

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Widen the schema to match reality: make the column Optional[int] / str as the data requires, or parse values in a select with .cast()/pw.coalesce defaults
  2. Clean at ingestion: apply pw.this.col.dt.strptime / pw.if_else(pw.python_re_match(...), ...) or a UDF normalizer before the checked expression
  3. Inspect the offending value named in the message ('Value X is not of type Y') in your raw source to find the exact row, then fix that data or its producer

Example fix

// before
class Input(pw.Schema):
    amount: int  # but some rows contain None or "12"
// after
class Input(pw.Schema):
    amount: Optional[int]

normalized = t.select(amount=pw.coalesce(pw.this.amount, 0))
Defensive patterns

Strategy: validation

Validate before calling

def row_matches_dtype(val, dtype) -> bool:
    # cheap precheck for scalar ingestion tests
    import datetime
    if dtype in (int, float, str, bool):
        return isinstance(val, dtype) and not isinstance(val, bool) != (dtype is bool)
    return True  # delegate complex dtypes to pathway's own checker

Type guard

from pathway.internals import dtype as dt

def value_matches(dtype: dt.DType, val) -> bool:
    return dtype.is_value_compatible(val)

Try / catch

try:
    run_pipeline()
except TypeError as e:
    if "is not of type" in str(e):
        # extract value+dtype from message, locate offending rows in the raw source
        ...

Prevention

When it happens

Trigger: A connector/schema declares a column as int but the data contains '42' or None; Optional-wrapped values flowing into a non-Optional column after unwrap; bytes vs str confusion; numpy scalars not matching the mapped dtype; Json payloads accessed with wrong assumed type.

Common situations: Dirty CSV/JSON inputs where a single row breaks the schema; schema declared optimistically from a sample; upstream producer changing a field type without notice; timezone-aware datetimes fed into a naive column.

Related errors


AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15). Data as JSON: /api/errors/dd6bcda52263c729. Report an issue: GitHub.