pathwaycom/pathway · error · ValueError

In reduce() all positional arguments have to be a ColumnRefe

Error message

In reduce() all positional arguments have to be a ColumnReference.

What it means

Table.reduce()'s argument preprocessor found a positional argument whose smart_name is None and which is not a string — i.e. it is neither a ColumnReference nor reducible to one. reduce() only accepts ColumnReference positionals; computed columns must be passed as named kwargs with a reducer expression.

Source

Thrown at python/pathway/internals/arg_handlers.py:188

        if kwargs:
            raise ValueError(
                "Join received extra kwargs.\n"
                + "You probably want to use TableLike.join(...).select(**kwargs) to compute output columns."
            )
        return (self, other, *on), processed_kwargs

    return handler


def reduce_args_handler(self, *args, **kwargs):
    for arg in args:
        if expr.smart_name(arg) is None:
            if isinstance(arg, str):
                raise ValueError(
                    f"Expected a ColumnReference, found a string. Did you mean this.{arg} instead of {repr(arg)}?"
                )
            else:
                raise ValueError(
                    "In reduce() all positional arguments have to be a ColumnReference."
                )
    return (self, *args), kwargs


def select_args_handler(self, *args, **kwargs):
    for arg in args:
        if not isinstance(arg, expr.ColumnReference):
            if isinstance(arg, str):
                raise ValueError(
                    f"Expected a ColumnReference, found a string. Did you mean this.{arg} instead of {repr(arg)}?"
                )
            else:
                raise ValueError(
                    "In select() all positional arguments have to be a ColumnReference."
                )
    return (self, *args), kwargs

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Keep only plain ColumnReference columns as positionals and move computations to kwargs: t.reduce(t.id, total=t.price + t.tax).
  2. If you don't need aggregation, use table.select(...) instead of reduce(...).
  3. If the argument is a derived expression, give it a name in kwargs with an appropriate reducer.

Example fix

# before
t.groupby(t.owner).reduce(t.owner, t.price + t.tax)

# after
t.groupby(t.owner).reduce(t.owner, total=pw.reducers.sum(t.price + t.tax))
Defensive patterns

Strategy: type-guard

Validate before calling

import pathway.internals.expression as expr
assert all(isinstance(a, expr.ColumnReference) for a in args), 'reduce() positionals must be plain column references; computations go to kwargs'

Type guard

import pathway.internals.expression as expr

def reduce_args_valid(args) -> bool:
    return all(isinstance(a, expr.ColumnReference) for a in args)

Prevention

When it happens

Trigger: Calling table.reduce(t.price + t.tax, total=...) with a binary expression positional, or passing an int/None/list positional such as table.reduce(1).

Common situations: Trying to pass arbitrary expressions or literal values positionally to reduce, expecting SQL SELECT-like behavior; mixing up select() (accepts expressions in kwargs) and reduce() (positional args must be bare column refs).

Related errors


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