{"record":{"id":"31c67da538316cda","repo":"pathwaycom/pathway","slug":"column-name-repr-colname-not-found-in-a-self","errorCode":null,"errorMessage":"Column name {repr(colname)} 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":86,"sourceCode":"        from pathway.internals import Table\n\n        if hasattr(Table, name) and name != \"id\":\n            raise ValueError(\n                f\"{name!r} is a method name. It is discouraged to use it as a column\"\n                + f\" name. If you really want to use it, use [{name!r}].\"\n            )\n        if name not in self._mapping:\n            raise AttributeError(f\"Column name {name!r} not found in {self!r}.\")\n        return self._mapping[name]\n\n    @trace_user_frame\n    @check_arg_types\n    def without(self, *cols: str | ColumnReference) -> TableSlice:\n        mapping = self._mapping.copy()\n        for col in cols:\n            colname = self._normalize(col)\n            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)","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table_slice.py#L68-L104","documentation":"Raised by TableSlice.without() when a column name passed to it does not exist in the slice's column mapping. The slice only contains the columns that were selected when it was created, so removing a column that was never part of the slice (or was already removed) fails immediately with a KeyError.","triggerScenarios":"Calling table.select(...).without('col') where 'col' is not among the selected columns; passing a ColumnReference (e.g. pw.this.col or table.col) whose normalized name is not in the mapping; calling without() twice with the same column, or with a column that only exists on the underlying table but not in the slice.","commonSituations":"Chaining select() then without() and forgetting that select() already dropped the column; typos or renamed columns (rename() before without()); referencing a column of the base table instead of the slice after a projection.","solutions":["Check the slice's columns first: print(list(table_slice.keys())) and only pass names that appear there","Use the underlying table if the column lives there: call without() before select(), or select only the columns you want instead of removing","Guard programmatically: table_slice.without(*[c for c in cols if c in table_slice.keys()])","Fix typos or use the current column name if a previous rename() changed it"],"exampleFix":"# before\nslice = table.select(\"a\", \"b\").without(\"c\")  # KeyError: 'c' not in slice\n\n# after\nslice = table.select(\"a\", \"b\")  # or table.without(\"c\").select(\"a\", \"b\")","handlingStrategy":"validation","validationCode":"cols_to_remove = [\"a\", \"b\"]\nknown = set(table_slice.keys())\nsafe = [c for c in cols_to_remove if c in known]\nmissing = [c for c in cols_to_remove if c not in known]\nassert not missing, f\"columns not in slice: {missing}\"\nslice2 = table_slice.without(*safe)","typeGuard":"def cols_exist_in_slice(slice_: TableSlice, cols: list[str]) -> bool:\n    known = set(slice_.keys())\n    return all(c in known for c in cols)","tryCatchPattern":"try:\n    slice2 = table_slice.without(\"col\")\nexcept KeyError as e:\n    raise ValueError(f\"column missing in slice, available: {list(table_slice.keys())}\") from e","preventionTips":["Derive removal lists from slice.keys(), never hardcode column names copied from other tables","Do projections with select() of wanted columns instead of without() of unwanted ones when unsure","Log slice.keys() once when building long select/without/rename chains"],"tags":["pathway","table-slice","column-not-found","keyerror"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}