{"record":{"id":"48dec90ffe7a62aa","repo":"pathwaycom/pathway","slug":"in-joinresult-groupby-all-arguments-have-to-be-a","errorCode":null,"errorMessage":"In JoinResult.groupby() all arguments have to be a ColumnReference.","messagePattern":"In JoinResult\\.groupby\\(\\) all arguments have to be a ColumnReference\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/joins.py","lineNumber":854,"sourceCode":"        ... 11   100  Alice    3    M\n        ... 12    90    Bob    1    L\n        ... 13    80    Tom    1   XL\n        ... ''')\n        >>> result = (t1.join(t2, t1.owner==t2.owner).groupby(pw.this.owner)\n        ...     .reduce(pw.this.owner, pairs = pw.reducers.count()))\n        >>> pw.debug.compute_and_print(result, include_id=False)\n        owner | pairs\n        Alice | 2\n        Bob   | 1\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 this.{arg} instead of {repr(arg)}?\"\n                    )\n                else:\n                    raise ValueError(\n                        \"In JoinResult.groupby() all arguments have to be a ColumnReference.\"\n                    )\n        from pathway.internals.groupbys import GroupedJoinResult\n\n        return GroupedJoinResult(\n            _join_result=self,\n            _args=args,\n            _id=id,\n        )\n\n    @trace_user_frame\n    @desugar\n    @arg_handler(handler=reduce_args_handler)\n    def reduce(\n        self, *args: expr.ColumnReference, **kwargs: expr.ColumnExpression\n    ) -> Table:\n        \"\"\"Reduce a join result to a single row.\n","sourceCodeStart":836,"sourceCodeEnd":872,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/joins.py#L836-L872","documentation":"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.","triggerScenarios":"t1.join(t2, ...).groupby(t1.owner + 1), groupby(some_int), or passing a reducer/expression object instead of a plain column reference.","commonSituations":"Trying to group by a computed expression directly (must be materialized with select/with_columns first); passing unrolled *args that contain non-column values.","solutions":["Materialize computed keys first: t = t.with_columns(key=expr) then .groupby(t.key)","Pass only plain column references (pw.this.x / table.x) as positional args"],"exampleFix":"# before\nres = t1.join(t2, t1.owner == t2.owner).groupby(t1.owner.lower())\n\n# after\nbase = t1.join(t2, t1.owner == t2.owner).with_columns(owner_lc=t1.owner.lower())\nres = base.groupby(base.owner_lc)","handlingStrategy":"type-guard","validationCode":"from pathway.internals import expr\n\nrefs = [a for a in args]\nassert all(isinstance(a, expr.ColumnReference) for a in refs), \"groupby positional args must be column references\"","typeGuard":"from pathway.internals import expr\n\ndef all_column_references(args) -> bool:\n    return all(isinstance(a, expr.ColumnReference) for a in args)","tryCatchPattern":null,"preventionTips":["Materialize computed grouping keys with with_columns before groupby","Keep positional args to plain column references; put aggregations in kwargs"],"tags":["pathway","join","groupby","api-misuse","type-error"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}