{"record":{"id":"e782c4d5cfac3c94","repo":"pathwaycom/pathway","slug":"table-groupby-received-id-argument-and-is-groupe","errorCode":null,"errorMessage":"Table.groupby() received id argument and is grouped by a single column, but the arguments are not equal.\nConsider using <table>.groupby(id=...), skipping the positional argument.","messagePattern":"Table\\.groupby\\(\\) received id argument and is grouped by a single column, but the arguments are not equal\\.\nConsider using <table>\\.groupby\\(id=\\.\\.\\.\\), skipping the positional argument\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table.py","lineNumber":1243,"sourceCode":"        ... ''')\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(\n                        \"All Table.groupby() arguments have to be a ColumnReference.\"\n                    )\n\n        self._check_for_disallowed_types(*args)","sourceCodeStart":1225,"sourceCodeEnd":1261,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table.py#L1225-L1261","documentation":"When Table.groupby() receives both a single positional column and id=, Pathway compares the underlying column objects (args[0]._column != id._column). If they are not the very same column, ValueError is raised: passing two different single columns (one positional, one as id) is ambiguous — the fix is to pass the intended column only via id=.","triggerScenarios":"t.groupby(t.a, id=t.b) with a != b; t.groupby(id=t.id, *args left over from a refactor) where the positional column is a transform of the id column rather than the identical ColumnReference.","commonSituations":"Refactoring a call from t.groupby(t.id) to t.groupby(id=t.id) and leaving the positional argument in; passing a copy/derived reference that is a different column object.","solutions":["Remove the positional argument and keep only id=: t.groupby(id=t.a)","Or remove id= and keep the plain positional column if custom ids are not needed"],"exampleFix":"# before\ng = t.groupby(t.key, id=t.user_id)  # two different columns -> ValueError\n\n# after\ng = t.groupby(id=t.user_id)","handlingStrategy":"validation","validationCode":"def id_matches_single_arg(args, id) -> bool:\n    return id is None or len(args) != 1 or args[0]._column == id._column","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass the grouping id column exclusively via id=, never also positionally","Clean up leftover positional args when refactoring to id= form"],"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"}