{"record":{"id":"a908ea8f626d9fde","repo":"pathwaycom/pathway","slug":"column-name-repr-old-not-found-in-a-self","errorCode":null,"errorMessage":"Column name {repr(old)} not found in a {self}.","messagePattern":"Column name (.+?) not found in a (.+?)\\.","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table_slice.py","lineNumber":103,"sourceCode":"            if colname not in mapping:\n                raise KeyError(f\"Column name {repr(colname)} not found in a {self}.\")\n            mapping.pop(colname)\n        return TableSlice(mapping, self._table)\n\n    @trace_user_frame\n    @check_arg_types\n    def rename(\n        self,\n        rename_dict: dict[str | ColumnReference, str | ColumnReference],\n    ) -> TableSlice:\n        rename_dict_normalized = {\n            self._normalize(old): self._normalize(new)\n            for old, new in rename_dict.items()\n        }\n        mapping = self._mapping.copy()\n        for old in rename_dict_normalized.keys():\n            if old not in mapping:\n                raise KeyError(f\"Column name {repr(old)} not found in a {self}.\")\n            mapping.pop(old)\n        for old, new in rename_dict_normalized.items():\n            mapping[new] = self._mapping[old]\n        return TableSlice(mapping, self._table)\n\n    @trace_user_frame\n    @check_arg_types\n    def with_prefix(self, prefix: str) -> TableSlice:\n        return self.rename({name: prefix + name for name in self.keys()})\n\n    @trace_user_frame\n    @check_arg_types\n    def with_suffix(self, suffix: str) -> TableSlice:\n        return self.rename({name: name + suffix for name in self.keys()})\n\n    @trace_user_frame\n    def ix(self, expression, *, optional: bool = False, context=None) -> TableSlice:\n        new_table = self._table.ix(expression, optional=optional, context=context)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table_slice.py#L85-L121","documentation":"Raised by TableSlice.rename() when a key of rename_dict does not match any column in the slice. rename() normalizes both keys and values (strings or ColumnReferences) and then verifies every old name exists in the slice mapping before rebuilding it.","triggerScenarios":"Calling table.select('a','b').rename({'x': 'y'}) where 'x' is not a selected column; renaming with pw.this.x or table.x references for a column not in the slice; renaming a column that an earlier without() already removed.","commonSituations":"Copy-pasting a rename dictionary from a longer table onto a projected slice; typos in old names; renaming after the column was dropped or renamed earlier in the chain.","solutions":["Print list(table_slice.keys()) and make every key of rename_dict one of those names","If the column exists on the base table, do the rename on the table before select(), or select the column into the slice first","Guard programmatically: only rename entries whose key is present: table_slice.rename({k: v for k, v in rename_dict.items() if k in table_slice.keys()})","Check for earlier rename/without calls in the chain that changed the column set"],"exampleFix":"# before\nslice = table.select(\"a\", \"b\").rename({\"c\": \"c2\"})  # KeyError\n\n# after\nslice = table.rename({\"c\": \"c2\"}).select(\"a\", \"b\")\n# or simply\nslice = table.select(\"a\", \"b\").rename({\"a\": \"a2\"})","handlingStrategy":"validation","validationCode":"rename_dict = {\"x\": \"y\"}\nknown = set(table_slice.keys())\nbad_keys = [k for k in rename_dict if k not in known]\nassert not bad_keys, f\"rename keys not in slice: {bad_keys}\"","typeGuard":"def rename_keys_valid(slice_: TableSlice, rename_dict: dict) -> bool:\n    return all(k in slice_.keys() for k in rename_dict)","tryCatchPattern":"try:\n    slice2 = table_slice.rename(rename_dict)\nexcept KeyError:\n    valid = {k: v for k, v in rename_dict.items() if k in table_slice.keys()}\n    slice2 = table_slice.rename(valid)","preventionTips":["Rename on the full table before projecting with select()","Keep a single source-of-truth mapping of column names shared by rename dictionaries","After every rename/without, re-derive names from slice.keys() instead of stale lists"],"tags":["pathway","table-slice","rename","column-not-found"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}