pathwaycom/pathway · error · KeyError

Column name {repr(colname)} not found in a {self}.

Error message

Column name {repr(colname)} not found in a {self}.

What it means

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.

Source

Thrown at python/pathway/internals/table_slice.py:86

        from pathway.internals import Table

        if hasattr(Table, name) and name != "id":
            raise ValueError(
                f"{name!r} is a method name. It is discouraged to use it as a column"
                + f" name. If you really want to use it, use [{name!r}]."
            )
        if name not in self._mapping:
            raise AttributeError(f"Column name {name!r} not found in {self!r}.")
        return self._mapping[name]

    @trace_user_frame
    @check_arg_types
    def without(self, *cols: str | ColumnReference) -> TableSlice:
        mapping = self._mapping.copy()
        for col in cols:
            colname = self._normalize(col)
            if colname not in mapping:
                raise KeyError(f"Column name {repr(colname)} not found in a {self}.")
            mapping.pop(colname)
        return TableSlice(mapping, self._table)

    @trace_user_frame
    @check_arg_types
    def rename(
        self,
        rename_dict: dict[str | ColumnReference, str | ColumnReference],
    ) -> TableSlice:
        rename_dict_normalized = {
            self._normalize(old): self._normalize(new)
            for old, new in rename_dict.items()
        }
        mapping = self._mapping.copy()
        for old in rename_dict_normalized.keys():
            if old not in mapping:
                raise KeyError(f"Column name {repr(old)} not found in a {self}.")
            mapping.pop(old)

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Check the slice's columns first: print(list(table_slice.keys())) and only pass names that appear there
  2. Use the underlying table if the column lives there: call without() before select(), or select only the columns you want instead of removing
  3. Guard programmatically: table_slice.without(*[c for c in cols if c in table_slice.keys()])
  4. Fix typos or use the current column name if a previous rename() changed it

Example fix

# before
slice = table.select("a", "b").without("c")  # KeyError: 'c' not in slice

# after
slice = table.select("a", "b")  # or table.without("c").select("a", "b")
Defensive patterns

Strategy: validation

Validate before calling

cols_to_remove = ["a", "b"]
known = set(table_slice.keys())
safe = [c for c in cols_to_remove if c in known]
missing = [c for c in cols_to_remove if c not in known]
assert not missing, f"columns not in slice: {missing}"
slice2 = table_slice.without(*safe)

Type guard

def cols_exist_in_slice(slice_: TableSlice, cols: list[str]) -> bool:
    known = set(slice_.keys())
    return all(c in known for c in cols)

Try / catch

try:
    slice2 = table_slice.without("col")
except KeyError as e:
    raise ValueError(f"column missing in slice, available: {list(table_slice.keys())}") from e

Prevention

When it happens

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

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

Related errors


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