{"record":{"id":"fc7e753ea7c6c483","repo":"pathwaycom/pathway","slug":"column-old-name-does-not-exist-in-a-given-table","errorCode":null,"errorMessage":"Column {old_name} does not exist in a given table.","messagePattern":"Column (.+?) does not exist in a given table\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table.py","lineNumber":2049,"sourceCode":"        ... 10  | Alice | 1\n        ... 9   | Bob   | 1\n        ... 8   | Alice | 2\n        ... ''')\n        >>> t2 = t1.rename_columns(years_old=t1.age, animal=t1.pet)\n        >>> pw.debug.compute_and_print(t2, include_id=False)\n        owner | years_old | animal\n        Alice | 8         | 2\n        Alice | 10        | 1\n        Bob   | 9         | 1\n        \"\"\"\n        mapping: dict[str, str] = {}\n        for new_name, old_name_col in kwargs.items():\n            if isinstance(old_name_col, expr.ColumnReference):\n                old_name = old_name_col.name\n            else:\n                old_name = old_name_col\n            if old_name not in self._columns:\n                raise ValueError(f\"Column {old_name} does not exist in a given table.\")\n            mapping[new_name] = old_name\n        renamed_columns = self._columns.copy()\n        for new_name, old_name in mapping.items():\n            renamed_columns.pop(old_name)\n        for new_name, old_name in mapping.items():\n            renamed_columns[new_name] = self._columns[old_name]\n\n        columns_wrapped = {\n            name: self._wrap_column_in_context(\n                self._rowwise_context,\n                column,\n                mapping[name] if name in mapping else name,\n            )\n            for name, column in renamed_columns.items()\n        }\n        return self._with_same_universe(*columns_wrapped.items())\n\n    @check_arg_types","sourceCodeStart":2031,"sourceCodeEnd":2067,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table.py#L2031-L2067","documentation":"Raised by Table.rename() when one of the kwargs maps a new name to an old column name (string or ColumnReference) that does not exist in the table. rename only renames existing columns; it cannot introduce or alias computed expressions.","triggerScenarios":"t.rename(pet_name='pet') where 'pet' is not a column (typo, renamed earlier, or column is actually 'animal'); also passing pw.this.wrong_col as the old name.","commonSituations":"Typos in old column names; renaming after a previous rename already changed the name; schemas that differ between dev and prod connectors; copy-pasting rename maps between tables.","solutions":["Check actual column names: print(t.column_names()) and fix the old-name key","If using ColumnReference, make sure it comes from this table (t['animal'], not another table's column)","Chain renames in dependency order — after t.rename(a='b') the name 'b' no longer exists","If you wanted to add a computed column, use with_columns instead of rename"],"exampleFix":"# before\nt2 = t.rename(pet_name='pet')  # column is actually 'animal'\n\n# after\nt2 = t.rename(pet_name='animal')","handlingStrategy":"validation","validationCode":"def rename_safe(t, **mapping):\n    bad = [old for old in mapping.values()\n           if (old.name if hasattr(old, 'name') else old) not in t._columns]\n    assert not bad, f'unknown columns: {bad}'\n    return t.rename(**mapping)","typeGuard":null,"tryCatchPattern":"try:\n    t2 = t.rename(new='old')\nexcept ValueError as e:\n    if 'does not exist' in str(e):\n        print(t.column_names()); raise","preventionTips":["Print column_names() before writing rename maps","Derive rename keys programmatically from t.column_names() where possible","Remember rename invalidates old names for later chained renames"],"tags":["pathway","rename","columns","schema"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}