pathwaycom/pathway · error · TypeError
Pathway doesn't support casting {source_type} to {target_typ
Error message
Pathway doesn't support casting {source_type} to {target_type}. What it means
The cast expression evaluator first tries cheap paths (no-op casts, equivalent dtypes, NONE into Optional, anything into Any), then consults the registered cast-operator mapping. If no cast handler exists between the source and target dtype, it raises this TypeError: Pathway simply does not support that conversion via .cast().
Source
Thrown at python/pathway/internals/graph_runner/expression_evaluator.py:575
target_type = expression._return_type
source_type = dt.normalize_pointers(source_type)
target_type = dt.normalize_pointers(target_type)
if (
dt.dtype_equivalence(target_type, source_type)
or dt.dtype_equivalence(dt.Optional(source_type), target_type)
or (source_type == dt.NONE and isinstance(target_type, dt.Optional))
or target_type == dt.ANY
):
return arg # then cast is noop
if (
result_expression := get_cast_operators_mapping(
arg, source_type, target_type
)
) is not None:
return result_expression
raise TypeError(
f"Pathway doesn't support casting {source_type} to {target_type}."
)
def eval_convert(
self,
expression: expr.ConvertExpression,
eval_state: RowwiseEvalState | None = None,
):
expr = self.eval_expression(expression._expr, eval_state=eval_state)
default = self.eval_expression(expression._default, eval_state=eval_state)
unwrap = expression._unwrap
source_type = expression._expr._dtype
target_type = expression._return_type
if (
dt.dtype_equivalence(target_type, source_type)
or dt.dtype_equivalence(dt.Optional(source_type), target_type)
or (source_type == dt.NONE and isinstance(target_type, dt.Optional))View on GitHub (pinned to fa2f74a464)
Solutions
- For Json/Any sources use Json accessors or conversion expressions (pw.Json.as_int(), dt parsing helpers) instead of .cast()
- Convert via an intermediate supported step: first cast to a compatible dtype that is registered (e.g. int->float), or format datetimes with dt methods rather than casting
- Fix the schema at ingestion so the expensive cast is unnecessary; use Optional only where the engine supports the inner cast
Example fix
// before value = pw.this.payload.cast(int) # payload is pw.Json // after value = pw.this.payload.as_int()
Defensive patterns
Strategy: type-guard
Validate before calling
KNOWN_CASTS = {(int, float), (float, int), (str, str), (int, str), (float, str)}
def cast_supported(src, dst) -> bool:
return (src, dst) in KNOWN_CASTS Type guard
def is_directly_castable(src_dtype, dst_dtype) -> bool:
# conservative check: only primitives of the same family or identical dtypes
return src_dtype == dst_dtype or {str(src_dtype), str(dst_dtype)} <= {'int', 'float'} Try / catch
try:
pw.this.col.cast(target)
except TypeError as e:
if "support casting" in str(e):
# fall back to a UDF conversion or Json accessor
... Prevention
- Do not treat .cast() as python's int()/str(); use it only for registered pairs
- Convert Json fields with accessors (as_int/as_float) instead of casting
- Fix types at the schema/connector level so casts are rarely needed
When it happens
Trigger: pw.this.col.cast(str) where col is a Pointer or Json; casting Any/Json directly to a concrete dtype (unsupported — Json needs its own accessors); casting between unrelated types like bool->str, bytes->int; casting DateTimeNaive<->DateTimeUtc; casting to Optional-of-unsupported inner type.
Common situations: Assuming .cast() behaves like str()/int() in python and works between anything; coercing Json fields by casting instead of using Json accessors; cleaning up badly-typed connector schemas with blanket casts.
Related errors
- Pathway does not support using binary operator {expression._
- Pathway doesn't support converting {source_type} to {target_
- Column of type {dtypes[0]} has no attribute {expression._nam
- Cannot flatten column of type {dtype}.
- Unsupported type {input_type}, use pw.DATE_TIME_UTC or pw.DA
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/86f3a72df2709aca.
Report an issue: GitHub.