pathwaycom/pathway · error · ValueError
Table.groupby() cannot have id argument when grouping by mul
Error message
Table.groupby() cannot have id argument when grouping by multiple columns.
What it means
In Table.groupby(), an id= keyword names the single column whose values become the group ids. Combining id= with more than one positional grouping column is contradictory (len(args) > 1 after instance folding), so ValueError is raised telling you not to pass id together with multiple columns.
Source
Thrown at python/pathway/internals/table.py:1239
... 10 | Alice | dog
... 9 | Bob | dog
... 8 | Alice | cat
... 7 | Bob | dog
... ''')
>>> t2 = t1.groupby(t1.pet, t1.owner).reduce(t1.owner, t1.pet, ageagg=pw.reducers.sum(t1.age))
>>> pw.debug.compute_and_print(t2, include_id=False)
owner | pet | ageagg
Alice | cat | 8
Alice | dog | 10
Bob | dog | 16
"""
if instance is not None:
args = (*args, instance)
if id is not None:
if len(args) == 0:
args = (id,)
elif len(args) > 1:
raise ValueError(
"Table.groupby() cannot have id argument when grouping by multiple columns."
)
elif args[0]._column != id._column:
raise ValueError(
"Table.groupby() received id argument and is grouped by a single column,"
+ " but the arguments are not equal.\n"
+ "Consider using <table>.groupby(id=...), skipping the positional argument."
)
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 <table>.{arg}"
+ f" instead of {repr(arg)}?"
)
else:
raise ValueError(View on GitHub (pinned to fa2f74a464)
Solutions
- Drop the id= argument when grouping by multiple columns
- If you need custom ids, group by exactly one column and pass it via id= only: t.groupby(id=t.a)
- For instance-based windows, use t.groupby(..., instance=t.x) without id
Example fix
# before result = t.groupby(t.owner, t.pet, id=t.id).reduce(...) # after result = t.groupby(t.owner, t.pet).reduce(...)
Defensive patterns
Strategy: validation
Validate before calling
def groupby_args_ok(args, id) -> bool:
return id is None or len(args) <= 1 Prevention
- Pass id= only with zero other grouping columns
- Remember instance= counts toward the argument list
When it happens
Trigger: t.groupby(t.a, t.b, id=t.c); t.groupby(t.a, instance=..., id=...) where instance plus a positional arg already makes args longer than one; id combined with several columns for windowing-by-instance patterns.
Common situations: Adapting instance/window groupby examples and keeping id from a simpler example; forgetting that instance also appends to args.
Related errors
- You cannot use {dep.to_column_expression()} in this reduce s
- You cannot use {dep.to_column_expression()} in this context.
- Expected a ColumnReference, found a string. Did you mean thi
- In JoinResult.groupby() all arguments have to be a ColumnRef
- Table.groupby() received id argument and is grouped by a sin
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/722ccd7ee61cc509.
Report an issue: GitHub.