pathwaycom/pathway · error · ValueError

TableSlice method arguments should refer to table of which t

Error message

TableSlice method arguments should refer to table of which the slice was created.

What it means

Raised by TableSlice._normalize() when a ColumnReference is bound to a Table object different from the table the slice was created from. Slice methods only accept references that belong to the slice's own table, which prevents silently mixing columns from unrelated tables.

Source

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

        return TableSlice(
            {name: new_table[colref._name] for name, colref in self._mapping.items()},
            new_table,
        )

    @property
    def slice(self):
        return self

    def _normalize(self, arg: str | ColumnReference):
        if isinstance(arg, ColumnReference):
            if isinstance(arg.table, ThisMetaclass):
                if arg.table != this:
                    raise ValueError(
                        f"TableSlice expects {repr(arg.name)} or this.{arg.name} argument as column reference."
                    )
            else:
                if arg.table != self._table:
                    raise ValueError(
                        "TableSlice method arguments should refer to table of which the slice was created."
                    )
            return arg.name
        else:
            return arg

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Pass plain strings for column names on the slice's own table: without('y') instead of table_b.y
  2. Create the reference from the same table the slice came from: table_a.y, not table_b.y
  3. After a join, use the join result's references (e.g. table_b['y'] on the joined table) or strings, matching the slice's origin

Example fix

# before
slice = table_a.select("x")
slice.without(table_b.y)  # ValueError: reference belongs to another table

# after
slice.without("y")
# or, if the column is on table_a:
slice.without(table_a.y)
Defensive patterns

Strategy: type-guard

Validate before calling

def ref_belongs_to_table(ref, table) -> bool:
    return getattr(ref, "table", None) is table

# usage
assert ref_belongs_to_table(table_b.y, table_a), "reference from wrong table"

Type guard

def ref_belongs_to_table(ref, table) -> bool:
    return getattr(ref, "table", None) is table

Try / catch

try:
    slice2 = table_slice.without(ref)
except ValueError as e:
    if "should refer to table" in str(e):
        slice2 = table_slice.without(ref.name)
    else:
        raise

Prevention

When it happens

Trigger: Passing table_b.col into a slice created from table_a (e.g. table_a.select('x').without(table_b.y)); passing references from a copy or a derived/reduced table object; mixing references after a join where the reference points at one of the input tables.

Common situations: Multi-table pipelines where similarly named columns exist on several tables; refactorings that swapped variable names so a slice and a reference no longer share the same Table instance; join results where columns must be referenced via the joined table.

Related errors


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