{"record":{"id":"722ccd7ee61cc509","repo":"pathwaycom/pathway","slug":"table-groupby-cannot-have-id-argument-when-group","errorCode":null,"errorMessage":"Table.groupby() cannot have id argument when grouping by multiple columns.","messagePattern":"Table\\.groupby\\(\\) cannot have id argument when grouping by multiple columns\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table.py","lineNumber":1239,"sourceCode":"        ... 10  | Alice | dog\n        ... 9   | Bob   | dog\n        ... 8   | Alice | cat\n        ... 7   | Bob   | dog\n        ... ''')\n        >>> t2 = t1.groupby(t1.pet, t1.owner).reduce(t1.owner, t1.pet, ageagg=pw.reducers.sum(t1.age))\n        >>> pw.debug.compute_and_print(t2, include_id=False)\n        owner | pet | ageagg\n        Alice | cat | 8\n        Alice | dog | 10\n        Bob   | dog | 16\n        \"\"\"\n        if instance is not None:\n            args = (*args, instance)\n        if id is not None:\n            if len(args) == 0:\n                args = (id,)\n            elif len(args) > 1:\n                raise ValueError(\n                    \"Table.groupby() cannot have id argument when grouping by multiple columns.\"\n                )\n            elif args[0]._column != id._column:\n                raise ValueError(\n                    \"Table.groupby() received id argument and is grouped by a single column,\"\n                    + \" but the arguments are not equal.\\n\"\n                    + \"Consider using <table>.groupby(id=...), skipping the positional argument.\"\n                )\n\n        for arg in args:\n            if not isinstance(arg, expr.ColumnReference):\n                if isinstance(arg, str):\n                    raise ValueError(\n                        f\"Expected a ColumnReference, found a string. Did you mean <table>.{arg}\"\n                        + f\" instead of {repr(arg)}?\"\n                    )\n                else:\n                    raise ValueError(","sourceCodeStart":1221,"sourceCodeEnd":1257,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table.py#L1221-L1257","documentation":"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.","triggerScenarios":"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.","commonSituations":"Adapting instance/window groupby examples and keeping id from a simpler example; forgetting that instance also appends to args.","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"],"exampleFix":"# before\nresult = t.groupby(t.owner, t.pet, id=t.id).reduce(...)\n\n# after\nresult = t.groupby(t.owner, t.pet).reduce(...)","handlingStrategy":"validation","validationCode":"def groupby_args_ok(args, id) -> bool:\n    return id is None or len(args) <= 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass id= only with zero other grouping columns","Remember instance= counts toward the argument list"],"tags":["groupby","api-misuse","pathway"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}