pathwaycom/pathway · error · TypeError
Pathway does not support using unary operator {operator_fun.
Error message
Pathway does not support using unary operator {operator_fun.__name__} on column of type {expression._expr._dtype.typehint}.\nIt refers to the following expression:\n{expression_info} What it means
Raised by the type interpreter when a unary operator (e.g. ~, -, +) is applied to a column whose dtype has no mapping for that operator. Pathway type-checks expressions eagerly; since unary operators are only defined for specific dtypes (mostly numbers and bools), applying one to e.g. a str or Json column fails at graph-construction time with the operator name, the column type, and a trace of the offending expression.
Source
Thrown at python/pathway/internals/type_interpreter.py:92
if state.check_colref_to_unoptionalize_from_colrefs(expression):
return dt.unoptionalize(dtype)
return dtype
def eval_unary_op(
self,
expression: expr.ColumnUnaryOpExpression,
state: TypeInterpreterState | None = None,
**kwargs,
) -> expr.ColumnUnaryOpExpression:
expression = super().eval_unary_op(expression, state=state, **kwargs)
operand_dtype = expression._expr._dtype
operator_fun = expression._operator
if (
dtype := get_unary_operators_mapping(operator_fun, operand_dtype)
) is not None:
return _wrap(expression, dtype)
expression_info = get_expression_info(expression)
raise TypeError(
f"Pathway does not support using unary operator {operator_fun.__name__}"
+ f" on column of type {expression._expr._dtype.typehint}.\n"
+ "It refers to the following expression:\n"
+ expression_info
)
def eval_binary_op(
self,
expression: expr.ColumnBinaryOpExpression,
state: TypeInterpreterState | None = None,
**kwargs,
) -> expr.ColumnBinaryOpExpression:
expression = super().eval_binary_op(expression, state=state, **kwargs)
left_dtype = expression._left._dtype
right_dtype = expression._right._dtype
return _wrap(
expression,
self._eval_binary_op(View on GitHub (pinned to fa2f74a464)
Solutions
- Cast the column to a supported type first: pw.this.col.astype(int) (or pw.cast_to) before the operator
- For Optional columns, handle the None case explicitly with pw.if_else(pw.this.col.is_not_none(), -pw.this.col, None) or unwrap after a default
- Replace bitwise ~ on non-bool columns with pw.this.col != True or a comparison appropriate to the type
- Do the transformation in .apply() with Python semantics if Pathway-level typing is too strict
Example fix
# before table = table.select(value=-pw.this.name) # str does not support unary '-' # after table = table.select(value=-pw.this.amount) # numeric column # or table = table.select(value=pw.this.name.apply(lambda s: -s))
Defensive patterns
Strategy: type-guard
Validate before calling
import pathway as pw
def unary_op_supported(dtype, op: str) -> bool:
numeric = dtype in (pw.typehints.Int(), pw.typehints.Float())
if op in ("neg", "pos", "invert"):
return numeric or (op == "invert" and dtype == pw.typehints.Bool())
return False
# check before applying: unary_op_supported(pw.typehints.Float(), "neg") Type guard
def can_negate(dtype) -> bool:
import pathway as pw
th = dtype
return th.equivalent_to(pw.typehints.Float()) or th.equivalent_to(pw.typehints.Int()) Try / catch
try:
out = t.select(v=-pw.this.col)
except TypeError:
out = t.select(v=pw.this.col.astype(float).apply(lambda x: -x)) Prevention
- Fix dtypes in input schemas instead of relying on inference
- Cast with astype before operators on heterogeneous or Optional columns
- Run a tiny pw.debug.compute_and_print on a sample to surface type errors early
When it happens
Trigger: pw.this.flag.apply(lambda x: ~x) style is fine for bools, but -pw.this.name on a str column, ~pw.this.value on an int/float (bitwise not unsupported for floats), or applying unary minus to an Optional/Json column triggers it; also via overloaded operators inside select/with_columns.
Common situations: Porting pandas/SQL expressions where unary minus or bitwise not works on more types (e.g. - on strings coerces, ~ works on any truthy); Optional[int] columns where the operator must be applied after unwrap; JSON columns needing explicit cast before arithmetic.
Related errors
- Pathway does not support using binary operator {operator.__n
- Cannot change type from {right} to {left}.\npw.`declare_type
- Incompatible types in for a coalesce expression.\nThe types
- Cannot perform pathway.if_else on columns of types {then_dty
- {expression!r} can only be applied to JSON columns, but colu
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/2eb65be7cd0da207.
Report an issue: GitHub.