{"record":{"id":"50d7010ef040c58b","repo":"pathwaycom/pathway","slug":"table-cast-to-types-argument-name-has-to-be-an-e","errorCode":null,"errorMessage":"Table.cast_to_types() argument name has to be an existing table column name.","messagePattern":"Table\\.cast_to_types\\(\\) argument name has to be an existing table column name\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table.py","lineNumber":2268,"sourceCode":"                )\n        return self._with_schema(new_schema)\n\n    @trace_user_frame\n    @check_arg_types\n    def update_id_type(self, id_type, *, id_append_only: bool | None = None) -> Table:\n        id_type = dt.wrap(id_type)\n        assert isinstance(id_type, dt.Pointer)\n        return self._with_schema(\n            self.schema.with_id_type(id_type, append_only=id_append_only)\n        )\n\n    @check_arg_types\n    def cast_to_types(self, **kwargs: Any) -> Table:\n        \"\"\"Casts columns to types.\"\"\"\n\n        for name in kwargs.keys():\n            if name not in self.keys():\n                raise ValueError(\n                    \"Table.cast_to_types() argument name has to be an existing table column name.\"\n                )\n        from pathway.internals.common import cast\n\n        return self.with_columns(\n            **{key: cast(val, self[key]) for key, val in kwargs.items()}\n        )\n\n    @contextualized_operator\n    @check_arg_types\n    def _having(self, indexer: expr.ColumnReference) -> Table[TSchema]:\n        context = clmn.HavingContext(\n            orig_id_column=self._id_column,\n            key_column=indexer._column,\n            key_id_column=indexer._table._id_column,\n        )\n        return self._table_with_context(context)\n","sourceCodeStart":2250,"sourceCodeEnd":2286,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table.py#L2250-L2286","documentation":"Raised by Table.cast_to_types() when a kwarg names a column that does not exist in the table. cast_to_types converts values of existing columns to new types via pathway.internals.common.cast, so it cannot create new columns.","triggerScenarios":"t.cast_to_types(bad_name=int) where 'bad_name' is not among t.keys(); typos; renamed columns; schema drift after connector upgrade.","commonSituations":"Casting a column that was dropped by an earlier select; wrong table in a chained call; copy-pasted cast maps between pipelines with different schemas.","solutions":["List columns: print(t.column_names()) and correct the kwarg name","Ensure no select/without earlier in the chain removed the column; reorder operations","To add a new typed column, use with_columns with an explicit cast expression","To change id type, use update_id_type instead of cast_to_types"],"exampleFix":"# before\nt2 = t.cast_to_types(nmae=str)  # typo for 'name'\n\n# after\nt2 = t.cast_to_types(name=str)","handlingStrategy":"validation","validationCode":"def cast_to_types_safe(t, **kwargs):\n    unknown = set(kwargs) - set(t.keys())\n    assert not unknown, f'unknown columns: {unknown}'\n    return t.cast_to_types(**kwargs)","typeGuard":null,"tryCatchPattern":"try:\n    t2 = t.cast_to_types(**casts)\nexcept ValueError as e:\n    if 'existing table column name' in str(e):\n        casts = {k: v for k, v in casts.items() if k in t.keys()}\n        t2 = t.cast_to_types(**casts)","preventionTips":["Derive cast kwargs from t.column_names()","Place casts before any select/without that drops columns","Use update_id_type for pointer/id columns"],"tags":["pathway","typing","cast-to-types","columns"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}