{"record":{"id":"6f3caf8651144ff4","repo":"pathwaycom/pathway","slug":"in-joinresult-reduce-all-positional-arguments-ha","errorCode":null,"errorMessage":"In JoinResult.reduce() all positional arguments have to be a ColumnReference.","messagePattern":"In JoinResult\\.reduce\\(\\) all positional arguments have to be a ColumnReference\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/joins.py","lineNumber":909,"sourceCode":"        >>> t2 = pw.debug.table_from_markdown('''\n        ...     cost  owner  pet size\n        ... 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).reduce(total_pairs = pw.reducers.count())\n        >>> pw.debug.compute_and_print(result, include_id=False)\n        total_pairs\n        3\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.reduce() all positional arguments have to be a ColumnReference.\"\n                    )\n        return self.groupby().reduce(*args, **kwargs)\n\n    def _substitutions(\n        self,\n    ) -> tuple[Table, dict[expr.InternalColRef, expr.ColumnExpression]]:\n        return self._inner_table, {\n            int_ref: expression for int_ref, expression in self._columns_mapping.items()\n        }\n\n    @desugar\n    @arg_handler(handler=select_args_handler)\n    @contextualized_operator\n    @staticmethod\n    def _join(\n        context: clmn.JoinContext, *args: expr.ColumnReference, **kwargs: Any\n    ) -> Table:","sourceCodeStart":891,"sourceCodeEnd":927,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/joins.py#L891-L927","documentation":"Non-string branch of JoinResult.reduce positional-arg validation: an argument is neither ColumnReference nor str (int, expression, reducer call, etc.), raising ValueError 'In JoinResult.reduce() all positional arguments have to be a ColumnReference.' Reduce on a JoinResult delegates to groupby().reduce(...), so the same rules apply.","triggerScenarios":"reduce(t1.owner + 1, n=pw.reducers.count()) or reduce(42, ...) — anything that is not a plain column reference in a positional slot.","commonSituations":"Trying to project a computed column directly in reduce; accidentally passing a list of names with * unpacking where some element is not a column reference.","solutions":["Materialize computed columns with with_columns/select before the join-level reduce","Ensure every positional element is pw.this.<col> or <table>.<col>"],"exampleFix":"# before\nres = t1.join(t2, t1.owner == t2.owner).reduce(t1.amount * 2, n=pw.reducers.count())\n\n# after\nbase = t1.join(t2, t1.owner == t2.owner).with_columns(amount2=t1.amount * 2)\nres = base.reduce(base.amount2, n=pw.reducers.count())","handlingStrategy":"type-guard","validationCode":"from pathway.internals import expr\n\nassert all(isinstance(a, expr.ColumnReference) for a in args), \"positional reduce 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":["Create derived columns with with_columns before reduce instead of inlining expressions","When unpacking *args, verify every element is a column reference"],"tags":["pathway","join","reduce","api-misuse","type-error"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}