pathwaycom/pathway · error · ValueError

Table.cast_to_types() argument name has to be an existing ta

Error message

Table.cast_to_types() argument name has to be an existing table column name.

What it means

Raised by Table.cast_to_types() when a kwarg names a column that does not exist in the table. cast_to_types converts values of existing columns to new types via pathway.internals.common.cast, so it cannot create new columns.

Source

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

                )
        return self._with_schema(new_schema)

    @trace_user_frame
    @check_arg_types
    def update_id_type(self, id_type, *, id_append_only: bool | None = None) -> Table:
        id_type = dt.wrap(id_type)
        assert isinstance(id_type, dt.Pointer)
        return self._with_schema(
            self.schema.with_id_type(id_type, append_only=id_append_only)
        )

    @check_arg_types
    def cast_to_types(self, **kwargs: Any) -> Table:
        """Casts columns to types."""

        for name in kwargs.keys():
            if name not in self.keys():
                raise ValueError(
                    "Table.cast_to_types() argument name has to be an existing table column name."
                )
        from pathway.internals.common import cast

        return self.with_columns(
            **{key: cast(val, self[key]) for key, val in kwargs.items()}
        )

    @contextualized_operator
    @check_arg_types
    def _having(self, indexer: expr.ColumnReference) -> Table[TSchema]:
        context = clmn.HavingContext(
            orig_id_column=self._id_column,
            key_column=indexer._column,
            key_id_column=indexer._table._id_column,
        )
        return self._table_with_context(context)

View on GitHub (pinned to fa2f74a464)

Solutions

  1. List columns: print(t.column_names()) and correct the kwarg name
  2. Ensure no select/without earlier in the chain removed the column; reorder operations
  3. To add a new typed column, use with_columns with an explicit cast expression
  4. To change id type, use update_id_type instead of cast_to_types

Example fix

# before
t2 = t.cast_to_types(nmae=str)  # typo for 'name'

# after
t2 = t.cast_to_types(name=str)
Defensive patterns

Strategy: validation

Validate before calling

def cast_to_types_safe(t, **kwargs):
    unknown = set(kwargs) - set(t.keys())
    assert not unknown, f'unknown columns: {unknown}'
    return t.cast_to_types(**kwargs)

Try / catch

try:
    t2 = t.cast_to_types(**casts)
except ValueError as e:
    if 'existing table column name' in str(e):
        casts = {k: v for k, v in casts.items() if k in t.keys()}
        t2 = t.cast_to_types(**casts)

Prevention

When it happens

Trigger: t.cast_to_types(bad_name=int) where 'bad_name' is not among t.keys(); typos; renamed columns; schema drift after connector upgrade.

Common situations: Casting a column that was dropped by an earlier select; wrong table in a chained call; copy-pasted cast maps between pipelines with different schemas.

Related errors


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