{"record":{"id":"c226d22dc4554253","repo":"pathwaycom/pathway","slug":"cannot-perform-pathway-fill-error-on-columns-of-ty","errorCode":null,"errorMessage":"Cannot perform pathway.fill_error on columns of types {inner_dtype.typehint} and {replacement_dtype.typehint}.","messagePattern":"Cannot perform pathway\\.fill_error on columns of types (.+?) and (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/type_interpreter.py","lineNumber":635,"sourceCode":"        **kwargs,\n    ) -> expr.UnwrapExpression:\n        expression = super().eval_unwrap(expression, state=state, **kwargs)\n        dtype = expression._expr._dtype\n        self._check_for_disallowed_types(\"pathway.unwrap\", dtype)\n        return _wrap(expression, dt.unoptionalize(dtype))\n\n    def eval_fill_error(\n        self,\n        expression: expr.FillErrorExpression,\n        state: TypeInterpreterState | None = None,\n        **kwargs,\n    ) -> expr.FillErrorExpression:\n        expression = super().eval_fill_error(expression, state=state, **kwargs)\n        inner_dtype = expression._expr._dtype\n        replacement_dtype = expression._replacement._dtype\n        lca = dt.types_lca(inner_dtype, replacement_dtype, raising=False)\n        if lca is dt.ANY and inner_dtype is not dt.ANY:\n            raise TypeError(\n                \"Cannot perform pathway.fill_error on columns of types\"\n                + f\" {inner_dtype.typehint} and {replacement_dtype.typehint}.\"\n            )\n        return _wrap(expression, lca)\n\n    def _check_for_disallowed_types(self, name: str, *dtypes: dt.DType) -> None:\n        disallowed_dtypes: list[dt.DType] = []\n        for dtype in dtypes:\n            if isinstance(dtype, dt.Future):\n                disallowed_dtypes.append(dtype)\n        if disallowed_dtypes:\n            dtypes_repr = \", \".join(f\"{dtype.typehint}\" for dtype in disallowed_dtypes)\n            # adjust message if more than dt.Future is involved\n            raise TypeError(\n                f\"Cannot perform {name} when column of type {dtypes_repr} is involved.\"\n                + \" Consider applying `await_futures()` to the table used here.\"\n            )\n","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/type_interpreter.py#L617-L653","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a replacement of the same type as the column: pw.fill_error(t.int_col, -1)","For string sentinel output, cast the column to str first: pw.fill_error(t.col.astype(str), 'n/a')","If mixed types are truly wanted, cast the column to pw.Any before fill_error","For JSON columns use pw.Json-compatible replacements"],"exampleFix":"// before\nres = pw.fill_error(t.value, 'n/a')  # t.value is int\n\n// after\nres = pw.fill_error(t.value, -1)","handlingStrategy":"type-guard","validationCode":"from pathway.internals import dtype as dt\n\ndef fill_error_compatible(col, replacement) -> bool:\n    inner = col._column.dtype\n    rep = dt.wrap(type(replacement))\n    lca = dt.types_lca(inner, rep, raising=False)\n    return lca is not dt.ANY or inner is dt.ANY","typeGuard":"from pathway.internals import dtype as dt\n\ndef has_common_type(a: dt.DType, b: dt.DType) -> bool:\n    return dt.types_lca(a, b, raising=False) is not dt.ANY","tryCatchPattern":"try:\n    res = pw.fill_error(t.col, replacement)\nexcept TypeError as e:\n    if 'Cannot perform pathway.fill_error' in str(e):\n        res = pw.fill_error(t.col.astype(str), str(replacement))\n    else:\n        raise","preventionTips":["Match the replacement literal's Python type to the column dtype","Wrap fill_error calls in small helpers that check table.schema first","Prefer typed sentinels (-1, None with Optional) over string placeholders in numeric columns"],"tags":["pathway","types","fill-error","error-handling"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}