pathwaycom/pathway · error · ValueError

Column {old_name} does not exist in a given table.

Error message

Column {old_name} does not exist in a given table.

What it means

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.

Source

Thrown at python/pathway/internals/table.py:2049

        ... 10  | Alice | 1
        ... 9   | Bob   | 1
        ... 8   | Alice | 2
        ... ''')
        >>> t2 = t1.rename_columns(years_old=t1.age, animal=t1.pet)
        >>> pw.debug.compute_and_print(t2, include_id=False)
        owner | years_old | animal
        Alice | 8         | 2
        Alice | 10        | 1
        Bob   | 9         | 1
        """
        mapping: dict[str, str] = {}
        for new_name, old_name_col in kwargs.items():
            if isinstance(old_name_col, expr.ColumnReference):
                old_name = old_name_col.name
            else:
                old_name = old_name_col
            if old_name not in self._columns:
                raise ValueError(f"Column {old_name} does not exist in a given table.")
            mapping[new_name] = old_name
        renamed_columns = self._columns.copy()
        for new_name, old_name in mapping.items():
            renamed_columns.pop(old_name)
        for new_name, old_name in mapping.items():
            renamed_columns[new_name] = self._columns[old_name]

        columns_wrapped = {
            name: self._wrap_column_in_context(
                self._rowwise_context,
                column,
                mapping[name] if name in mapping else name,
            )
            for name, column in renamed_columns.items()
        }
        return self._with_same_universe(*columns_wrapped.items())

    @check_arg_types

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Check actual column names: print(t.column_names()) and fix the old-name key
  2. If using ColumnReference, make sure it comes from this table (t['animal'], not another table's column)
  3. Chain renames in dependency order — after t.rename(a='b') the name 'b' no longer exists
  4. If you wanted to add a computed column, use with_columns instead of rename

Example fix

# before
t2 = t.rename(pet_name='pet')  # column is actually 'animal'

# after
t2 = t.rename(pet_name='animal')
Defensive patterns

Strategy: validation

Validate before calling

def rename_safe(t, **mapping):
    bad = [old for old in mapping.values()
           if (old.name if hasattr(old, 'name') else old) not in t._columns]
    assert not bad, f'unknown columns: {bad}'
    return t.rename(**mapping)

Try / catch

try:
    t2 = t.rename(new='old')
except ValueError as e:
    if 'does not exist' in str(e):
        print(t.column_names()); raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15). Data as JSON: /api/errors/fc7e753ea7c6c483. Report an issue: GitHub.