{"record":{"id":"f32daac9bf614235","repo":"pathwaycom/pathway","slug":"pathway-doesn-t-support-converting-source-type-t","errorCode":null,"errorMessage":"Pathway doesn't support converting {source_type} to {target_type}.","messagePattern":"Pathway doesn't support converting (.+?) to (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/graph_runner/expression_evaluator.py","lineNumber":605,"sourceCode":"        source_type = expression._expr._dtype\n        target_type = expression._return_type\n\n        if (\n            dt.dtype_equivalence(target_type, source_type)\n            or dt.dtype_equivalence(dt.Optional(source_type), target_type)\n            or (source_type == dt.NONE and isinstance(target_type, dt.Optional))\n            or target_type == dt.ANY\n        ):\n            return expr\n\n        if (\n            result_expression := get_convert_operator(\n                expr, default, source_type, target_type, unwrap\n            )\n        ) is not None:\n            return result_expression\n\n        raise TypeError(\n            f\"Pathway doesn't support converting {source_type} to {target_type}.\"\n        )\n\n    def eval_declare(\n        self,\n        expression: expr.DeclareTypeExpression,\n        eval_state: RowwiseEvalState | None = None,\n    ):\n        return self.eval_expression(expression._expr, eval_state=eval_state)\n\n    def eval_coalesce(\n        self,\n        expression: expr.CoalesceExpression,\n        eval_state: RowwiseEvalState | None = None,\n    ):\n        dtype = self.expression_type(expression)\n        args: list[api.Expression] = []\n        for expr_arg in expression._args:","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/graph_runner/expression_evaluator.py#L587-L623","documentation":"eval_convert implements the type-conversion expression (used by .retag/declare/unwrap pipelines and the `convert` mechanism behind casts with a default). After skipping no-op conversions (equivalent dtypes, NONE->Optional, target Any), it looks up get_convert_operator for the (source, target, unwrap) combination; when none is registered it raises this TypeError, meaning that conversion path is not implemented.","triggerScenarios":"Using .cast(default=...) / convert-style expressions between dtype pairs with no registered converter (e.g. str->bytes with default, Json->int, bool->str); conversions crossing Optional boundaries with unwrap=True where the inner pair is unsupported.","commonSituations":"Calling API surfaces that route through ConvertExpression (type declarations with defaults, unwrap chains) on exotic dtype pairs; assuming every cast-with-fallback combination exists because plain cast works for some pairs.","solutions":["Reorder the conversion through supported hops (str -> int -> float, or via Json accessors) instead of one direct convert","Do the conversion inside a UDF where you control the python-level coercion, and annotate the supported return dtype","Drop the default/unwrap flags and handle failure rows explicitly with pw.if_else / filter so the registered converter path applies"],"exampleFix":"// before\nvalue = pw.this.col.cast(str, default='')  # unsupported pair, e.g. bytes->str with default\n// after\n@pw.udf(return_type=str)\ndef to_str(v: bytes | None) -> str:\n    return '' if v is None else v.decode('utf-8', 'replace')\n\nvalue = to_str(pw.this.col)","handlingStrategy":"fallback","validationCode":"SUPPORTED_CONVERSIONS = {(int, float), (float, int)}\n\ndef convert_supported(src, dst) -> bool:\n    return (src, dst) in SUPPORTED_CONVERSIONS","typeGuard":null,"tryCatchPattern":"try:\n    expr.cast(dst, default=d)\nexcept TypeError as e:\n    if \"support converting\" in str(e):\n        # fallback: do the conversion in a UDF with explicit error handling\n        ...","preventionTips":["Chain conversions through supported intermediate dtypes instead of one exotic jump","Prefer UDFs with annotated return types for non-standard conversions","Keep Optional/unwrap usage aligned with converters that actually exist"],"tags":["pathway","dtype","conversion","unwrap","expression"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}