pathwaycom/pathway · error · ValueError
You cannot use {dep.to_column_expression()} in this context.
Error message
You cannot use {dep.to_column_expression()} in this context. Its universe is different than the universe of the table the method was called on. You can use <table1>.with_universe_of(<table2>) to assign universe of <table2> to <table1> if you're sure their sets of keys are equal. What it means
Raised by Table._validate_expression when an expression passed to a table method depends (above any reducer) on a column whose universe differs from the table the method was called on. Pathway expressions are universe-scoped: a column from another table's row set cannot be evaluated row-wise on this table. The message suggests with_universe_of as the explicit escape hatch.
Source
Thrown at python/pathway/internals/table.py:2509
def _unsafe_promise_universe(self, other: TableLike) -> Table:
context = clmn.PromiseSameUniverseContext(self._id_column, other._id_column)
return self._table_with_context(context)
@contextualized_operator
def _unsafe_promise_universe_as_of_now(self, other: TableLike) -> Table:
"""Updates the universe of ``self`` to the universe of ``other``.
Stricter than _unsafe_promise_universe. Both universes have
to have updates to the same keys at the same processing time."""
context = clmn.PromiseSameUniverseAsOfNowContext(
self._id_column, other._id_column
)
return self._table_with_context(context)
def _validate_expression(self, expression: expr.ColumnExpression):
for dep in expression._dependencies_above_reducer():
if self._universe != dep._column.universe:
raise ValueError(
f"You cannot use {dep.to_column_expression()} in this context."
+ " Its universe is different than the universe of the table the method"
+ " was called on. You can use <table1>.with_universe_of(<table2>)"
+ " to assign universe of <table2> to <table1> if you're sure their"
+ " sets of keys are equal."
)
def _check_for_disallowed_types(self, *expressions: expr.ColumnExpression):
for expression in expressions:
dtype = self.eval_type(expression)
if isinstance(dtype, dt.Future):
raise TypeError(
f"Using column of type {dtype.typehint} is not allowed here."
+ " Consider applying `await_futures()` to the table first."
)
def _wrap_column_in_context(
self,View on GitHub (pinned to fa2f74a464)
Solutions
- Join the tables first, then use the joined columns: tj = t1.join(t2, t1.k == t2.k).select(t1.a, t2.b)
- If the universes are provably equal, assert it: t2 = t2.with_universe_of(t1) — but only when key sets truly match
- For aggregates from another table, reduce them (e.g. t2.reduce(cnt=pw.reducers.count())) so the dependency crosses universes via a reducer
- Check universes in tests with pw.debug.compute_and_print before asserting equality
Example fix
# before t3 = t1.with_columns(x=t2.value + 1) # different universes -> ValueError # after t3 = t1.join(t2, t1.key == t2.key).select(*pw.left, x=pw.right.value + 1)
Defensive patterns
Strategy: validation
Validate before calling
def same_universe(t1, t2) -> bool:
return t1._universe == t2._universe
# only use with_universe_of when this returns True in practice Try / catch
try:
t3 = t1.with_columns(x=expr_from_t2)
except ValueError as e:
if 'different than the universe' in str(e):
tj = t1.join(t2, t1.k == t2.k)
t3 = tj.select(*pw.left, x=pw.right.col + 1) Prevention
- Join before combining columns from two tables
- Never assume universes are equal without asserting via with_universe_of
- Reduce foreign aggregates with reducers instead of raw cross-universe columns
When it happens
Trigger: t1.with_columns(x=t2.col + 1) where t2 has a different universe than t1; using a column captured from another table inside filter/select/with_columns; using a non-reduced column from a different table after a groupby/join without proper context.
Common situations: Mixing columns of two tables in one expression instead of joining first; refactors that moved a column computation to a different table; forgetting that join result columns carry the joined universe.
Related errors
- direction argument of join should be of type asof_join.Direc
- The behavior argument of join should be of type pathway.temp
- The interval argument of a join should be of a type pathway.
- Join received extra kwargs. You probably want to use TableLi
- invalid expression in restricted context
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/c7393af22e4d943e.
Report an issue: GitHub.