pathwaycom/pathway · error · TypeError

Cannot perform pathway.fill_error on columns of types {inner

Error message

Cannot perform pathway.fill_error on columns of types {inner_dtype.typehint} and {replacement_dtype.typehint}.

What it means

TypeError raised when pathway.fill_error is applied and the least common type (LCA) of the column's inner dtype and the replacement value's dtype is ANY (i.e., they are incompatible), unless the column itself is already ANY. fill_error requires the replacement to be coercible to a common type with the values it replaces.

Source

Thrown at python/pathway/internals/type_interpreter.py:635

        **kwargs,
    ) -> expr.UnwrapExpression:
        expression = super().eval_unwrap(expression, state=state, **kwargs)
        dtype = expression._expr._dtype
        self._check_for_disallowed_types("pathway.unwrap", dtype)
        return _wrap(expression, dt.unoptionalize(dtype))

    def eval_fill_error(
        self,
        expression: expr.FillErrorExpression,
        state: TypeInterpreterState | None = None,
        **kwargs,
    ) -> expr.FillErrorExpression:
        expression = super().eval_fill_error(expression, state=state, **kwargs)
        inner_dtype = expression._expr._dtype
        replacement_dtype = expression._replacement._dtype
        lca = dt.types_lca(inner_dtype, replacement_dtype, raising=False)
        if lca is dt.ANY and inner_dtype is not dt.ANY:
            raise TypeError(
                "Cannot perform pathway.fill_error on columns of types"
                + f" {inner_dtype.typehint} and {replacement_dtype.typehint}."
            )
        return _wrap(expression, lca)

    def _check_for_disallowed_types(self, name: str, *dtypes: dt.DType) -> None:
        disallowed_dtypes: list[dt.DType] = []
        for dtype in dtypes:
            if isinstance(dtype, dt.Future):
                disallowed_dtypes.append(dtype)
        if disallowed_dtypes:
            dtypes_repr = ", ".join(f"{dtype.typehint}" for dtype in disallowed_dtypes)
            # adjust message if more than dt.Future is involved
            raise TypeError(
                f"Cannot perform {name} when column of type {dtypes_repr} is involved."
                + " Consider applying `await_futures()` to the table used here."
            )

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Use a replacement of the same type as the column: pw.fill_error(t.int_col, -1)
  2. For string sentinel output, cast the column to str first: pw.fill_error(t.col.astype(str), 'n/a')
  3. If mixed types are truly wanted, cast the column to pw.Any before fill_error
  4. For JSON columns use pw.Json-compatible replacements

Example fix

// before
res = pw.fill_error(t.value, 'n/a')  # t.value is int

// after
res = pw.fill_error(t.value, -1)
Defensive patterns

Strategy: type-guard

Validate before calling

from pathway.internals import dtype as dt

def fill_error_compatible(col, replacement) -> bool:
    inner = col._column.dtype
    rep = dt.wrap(type(replacement))
    lca = dt.types_lca(inner, rep, raising=False)
    return lca is not dt.ANY or inner is dt.ANY

Type guard

from pathway.internals import dtype as dt

def has_common_type(a: dt.DType, b: dt.DType) -> bool:
    return dt.types_lca(a, b, raising=False) is not dt.ANY

Try / catch

try:
    res = pw.fill_error(t.col, replacement)
except TypeError as e:
    if 'Cannot perform pathway.fill_error' in str(e):
        res = pw.fill_error(t.col.astype(str), str(replacement))
    else:
        raise

Prevention

When it happens

Trigger: pw.fill_error(t.col, 'n/a') where t.col is int and 'n/a' is str; fill_error with a float replacement on a bool column; any replacement whose type has no LCA with the column type other than ANY.

Common situations: Filling errors in numeric columns with string sentinels; filling datetime column errors with 0; filling a bool column with an int; replacement inferred as a different type by Python.

Related errors


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