{"record":{"id":"dd6bcda52263c729","repo":"pathwaycom/pathway","slug":"value-val-is-not-of-type-dtype","errorCode":null,"errorMessage":"Value {val} is not of type {dtype}.","messagePattern":"Value (.+?) is not of type (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/graph_runner/expression_evaluator.py","lineNumber":205,"sourceCode":"    def eval_expression(  # type: ignore[override]\n        self, expression: expr.ColumnExpression, **kwargs\n    ) -> expr.ColumnExpression:\n        expression = super().eval_expression(expression, **kwargs)\n\n        from pathway.internals.operator import RowTransformerOperator\n\n        if isinstance(expression, expr.ColumnReference):\n            if isinstance(\n                expression._column.lineage.source.operator, RowTransformerOperator\n            ):\n                return expression\n\n        dtype = expression._dtype\n\n        @udf(return_type=dtype, deterministic=True)\n        def test_type(val):\n            if not dtype.is_value_compatible(val):\n                raise TypeError(f\"Value {val} is not of type {dtype}.\")\n            return val\n\n        ret = test_type(expression)\n        assert isinstance(ret, expr.ApplyExpression)\n        ret._check_for_disallowed_types = False\n        ret._dtype = dtype\n\n        return ret\n\n\nclass RowwiseEvaluator(\n    ExpressionEvaluator, ExpressionVisitor, context_type=clmn.RowwiseContext\n):\n    def run(\n        self,\n        output_storage: Storage,\n        old_path: ColumnPath | None = ColumnPath.EMPTY,\n        disable_runtime_typechecking: bool = False,","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/graph_runner/expression_evaluator.py#L187-L223","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","Clean at ingestion: apply pw.this.col.dt.strptime / pw.if_else(pw.python_re_match(...), ...) or a UDF normalizer before the checked expression","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"],"exampleFix":"// before\nclass Input(pw.Schema):\n    amount: int  # but some rows contain None or \"12\"\n// after\nclass Input(pw.Schema):\n    amount: Optional[int]\n\nnormalized = t.select(amount=pw.coalesce(pw.this.amount, 0))","handlingStrategy":"validation","validationCode":"def row_matches_dtype(val, dtype) -> bool:\n    # cheap precheck for scalar ingestion tests\n    import datetime\n    if dtype in (int, float, str, bool):\n        return isinstance(val, dtype) and not isinstance(val, bool) != (dtype is bool)\n    return True  # delegate complex dtypes to pathway's own checker","typeGuard":"from pathway.internals import dtype as dt\n\ndef value_matches(dtype: dt.DType, val) -> bool:\n    return dtype.is_value_compatible(val)","tryCatchPattern":"try:\n    run_pipeline()\nexcept TypeError as e:\n    if \"is not of type\" in str(e):\n        # extract value+dtype from message, locate offending rows in the raw source\n        ...","preventionTips":["Declare schemas with Optional[...] for any column that can be missing or None","Spot-check real data against the schema before wiring connectors (dtype.is_value_compatible)","Normalize strings to concrete types at ingestion instead of trusting source types"],"tags":["pathway","dtype","data-quality","schema-mismatch","runtime"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}