{"record":{"id":"383d4813c3400495","repo":"pathwaycom/pathway","slug":"all-table-groupby-arguments-have-to-be-a-columnr","errorCode":null,"errorMessage":"All Table.groupby() arguments have to be a ColumnReference.","messagePattern":"All Table\\.groupby\\(\\) arguments have to be a ColumnReference\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table.py","lineNumber":1257,"sourceCode":"                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)\n        return groupbys.GroupedTable.create(\n            table=self,\n            grouping_columns=args,\n            last_column_is_instance=instance is not None,\n            set_id=id is not None,\n            sort_by=sort_by,\n            _filter_out_results_of_forgetting=_filter_out_results_of_forgetting,\n            _skip_errors=_skip_errors,\n            _is_window=_is_window,\n        )\n\n    @trace_user_frame\n    @desugar\n    @arg_handler(handler=reduce_args_handler)","sourceCodeStart":1239,"sourceCodeEnd":1275,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table.py#L1239-L1275","documentation":"The generic branch of groupby()'s argument validation: any positional argument that is neither a ColumnReference nor a string (e.g. int, plain value, arbitrary expression) raises ValueError('All Table.groupby() arguments have to be a ColumnReference.'). Grouping keys must be column references so Pathway can build the grouped universe.","triggerScenarios":"t.groupby(0); t.groupby(some_derived_expression) instead of first materializing it with with_columns; t.groupby(None) from an unset variable; passing a list object.","commonSituations":"Index-based grouping ported from pandas; forwarding an expression like t.a + t.b directly instead of a named column; None leaking from optional config.","solutions":["Materialize derived keys first: t = t.with_columns(key=t.a + t.b); then t.groupby(t.key)","Pass column references only (t.col / pw.this.col); wrap dynamic names with getattr","Check for None/unset variables before building the groupby call"],"exampleFix":"# before\ng = t.groupby(t.a + t.b)  # expression, not a reference -> ValueError\n\n# after\nt = t.with_columns(key=t.a + t.b)\ng = t.groupby(t.key)","handlingStrategy":"type-guard","validationCode":"from pathway.internals import expression as expr\n\ndef groupby_args_valid(args) -> bool:\n    return all(isinstance(a, expr.ColumnReference) for a in args)","typeGuard":"from pathway.internals import expression as expr\n\ndef is_column_ref(arg) -> bool:\n    return isinstance(arg, expr.ColumnReference)","tryCatchPattern":null,"preventionTips":["Materialize derived keys with with_columns before grouping","Never pass literals or raw expressions to groupby"],"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"}