{"record":{"id":"7e25888b24738210","repo":"pathwaycom/pathway","slug":"in-reduce-all-positional-arguments-have-to-be-a","errorCode":null,"errorMessage":"In reduce() all positional arguments have to be a ColumnReference.","messagePattern":"In reduce\\(\\) all positional arguments have to be a ColumnReference\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/arg_handlers.py","lineNumber":188,"sourceCode":"        if kwargs:\n            raise ValueError(\n                \"Join received extra kwargs.\\n\"\n                + \"You probably want to use TableLike.join(...).select(**kwargs) to compute output columns.\"\n            )\n        return (self, other, *on), processed_kwargs\n\n    return handler\n\n\ndef reduce_args_handler(self, *args, **kwargs):\n    for arg in args:\n        if expr.smart_name(arg) is None:\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 reduce() all positional arguments have to be a ColumnReference.\"\n                )\n    return (self, *args), kwargs\n\n\ndef select_args_handler(self, *args, **kwargs):\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 select() all positional arguments have to be a ColumnReference.\"\n                )\n    return (self, *args), kwargs\n","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/arg_handlers.py#L170-L206","documentation":"Table.reduce()'s argument preprocessor found a positional argument whose smart_name is None and which is not a string — i.e. it is neither a ColumnReference nor reducible to one. reduce() only accepts ColumnReference positionals; computed columns must be passed as named kwargs with a reducer expression.","triggerScenarios":"Calling table.reduce(t.price + t.tax, total=...) with a binary expression positional, or passing an int/None/list positional such as table.reduce(1).","commonSituations":"Trying to pass arbitrary expressions or literal values positionally to reduce, expecting SQL SELECT-like behavior; mixing up select() (accepts expressions in kwargs) and reduce() (positional args must be bare column refs).","solutions":["Keep only plain ColumnReference columns as positionals and move computations to kwargs: t.reduce(t.id, total=t.price + t.tax).","If you don't need aggregation, use table.select(...) instead of reduce(...).","If the argument is a derived expression, give it a name in kwargs with an appropriate reducer."],"exampleFix":"# before\nt.groupby(t.owner).reduce(t.owner, t.price + t.tax)\n\n# after\nt.groupby(t.owner).reduce(t.owner, total=pw.reducers.sum(t.price + t.tax))","handlingStrategy":"type-guard","validationCode":"import pathway.internals.expression as expr\nassert all(isinstance(a, expr.ColumnReference) for a in args), 'reduce() positionals must be plain column references; computations go to kwargs'","typeGuard":"import pathway.internals.expression as expr\n\ndef reduce_args_valid(args) -> bool:\n    return all(isinstance(a, expr.ColumnReference) for a in args)","tryCatchPattern":null,"preventionTips":["Remember the rule: reduce() positionals keep columns, kwargs compute new ones.","Use select() when no aggregation is needed."],"tags":["pathway","reduce","argument-validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}