pathwaycom/pathway · error · ValueError

In JoinResult.groupby() all arguments have to be a ColumnRef

Error message

In JoinResult.groupby() all arguments have to be a ColumnReference.

What it means

The non-string branch of JoinResult.groupby argument validation: a positional argument is neither expr.ColumnReference nor str (e.g. an int, a ColumnExpression like t.col + 1, or a raw Column), so ValueError 'In JoinResult.groupby() all arguments have to be a ColumnReference.' is raised. Unlike error 90, no this.<name> hint is possible.

Source

Thrown at python/pathway/internals/joins.py:854

        ... 11   100  Alice    3    M
        ... 12    90    Bob    1    L
        ... 13    80    Tom    1   XL
        ... ''')
        >>> result = (t1.join(t2, t1.owner==t2.owner).groupby(pw.this.owner)
        ...     .reduce(pw.this.owner, pairs = pw.reducers.count()))
        >>> pw.debug.compute_and_print(result, include_id=False)
        owner | pairs
        Alice | 2
        Bob   | 1
        """
        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 JoinResult.groupby() all arguments have to be a ColumnReference."
                    )
        from pathway.internals.groupbys import GroupedJoinResult

        return GroupedJoinResult(
            _join_result=self,
            _args=args,
            _id=id,
        )

    @trace_user_frame
    @desugar
    @arg_handler(handler=reduce_args_handler)
    def reduce(
        self, *args: expr.ColumnReference, **kwargs: expr.ColumnExpression
    ) -> Table:
        """Reduce a join result to a single row.

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Materialize computed keys first: t = t.with_columns(key=expr) then .groupby(t.key)
  2. Pass only plain column references (pw.this.x / table.x) as positional args

Example fix

# before
res = t1.join(t2, t1.owner == t2.owner).groupby(t1.owner.lower())

# after
base = t1.join(t2, t1.owner == t2.owner).with_columns(owner_lc=t1.owner.lower())
res = base.groupby(base.owner_lc)
Defensive patterns

Strategy: type-guard

Validate before calling

from pathway.internals import expr

refs = [a for a in args]
assert all(isinstance(a, expr.ColumnReference) for a in refs), "groupby positional args must be column references"

Type guard

from pathway.internals import expr

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

Prevention

When it happens

Trigger: t1.join(t2, ...).groupby(t1.owner + 1), groupby(some_int), or passing a reducer/expression object instead of a plain column reference.

Common situations: Trying to group by a computed expression directly (must be materialized with select/with_columns first); passing unrolled *args that contain non-column values.

Related errors


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