{"record":{"id":"7af0d5b6f74a255e","repo":"pathwaycom/pathway","slug":"you-cannot-use-dep-to-column-expression-in-thi-7af0d5","errorCode":null,"errorMessage":"You cannot use {dep.to_column_expression()} in this context. Its universe is different than the universe of the table the method was called on. You can use <table1>.with_universe_of(<table2>) to assign universe of <table2> to <table1> if you're sure their sets of keys are equal.","messagePattern":"You cannot use (.+?) in this context\\. Its universe is different than the universe of the table the method was called on\\. You can use <table1>\\.with_universe_of\\(<table2>\\) to assign universe of <table2> to <table1> if you're sure their sets of keys are equal\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/groupbys.py","lineNumber":266,"sourceCode":"    def _validate_expression(self, expression: expr.ColumnExpression):\n        for dep in expression._dependencies_above_reducer():\n            if (\n                not isinstance(dep._table, thisclass.ThisMetaclass)  # allow for ix\n                and dep.to_column_expression()._to_original()._to_internal()\n                not in self._grouping_columns\n            ):\n                raise ValueError(\n                    f\"You cannot use {dep.to_column_expression()} in this reduce statement.\\n\"\n                    + f\"Make sure that {dep.to_column_expression()} is used in a groupby or wrap it with a reducer, \"\n                    + f\"e.g. pw.reducers.count({dep.to_column_expression()})\"\n                )\n\n        for dep in expression._dependencies_below_reducer():\n            if (\n                self._joinable_to_group._universe\n                != dep.to_column_expression()._column.universe\n            ):\n                raise ValueError(\n                    f\"You cannot use {dep.to_column_expression()} in this context.\"\n                    + \" Its universe is different than the universe of the table the method\"\n                    + \" was called on. You can use <table1>.with_universe_of(<table2>)\"\n                    + \" to assign universe of <table2> to <table1> if you're sure their\"\n                    + \" sets of keys are equal.\"\n                )\n\n    @lru_cache\n    def _operator_dependencies(self) -> StableSet[table.Table]:\n        # TODO + grouping columns expression dependencies\n        return self._joinable_to_group._operator_dependencies()\n\n\nclass GroupedJoinResult(GroupedJoinable):\n    _substitution_desugaring: SubstitutionDesugaring\n    _groupby: GroupedTable\n\n    def __init__(","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/groupbys.py#L248-L284","documentation":"The second half of GroupBy._validate_expression: dependencies below a reducer must live on the same universe as the table the groupby was called on (self._joinable_to_group._universe). If a dep's column belongs to a different universe, ValueError explains the mismatch and points to <table1>.with_universe_of(<table2>) as the escape hatch for when key sets are provably equal.","triggerScenarios":"t.groupby(t.key).reduce(...) where the reducer argument or post-reducer expression references a column of a different table whose universe differs, e.g. mixing a column from t2 (built by a filter/join) into a reduce on t1 without universe alignment.","commonSituations":"Using ix/pointer lookups or join outputs inside reduce; combining columns from two tables that share keys by construction but not universe identity; migrating pandas merge-then-groupby code.","solutions":["If the two tables are guaranteed to have identical key sets, call t1.with_universe_of(t2) (or vice versa) before the groupby/reduce","Otherwise perform an explicit join first so all referenced columns live on one universe","Re-check that the referenced column really belongs to the table being grouped, not a leftover variable"],"exampleFix":"# before\nres = t1.groupby(t1.key).reduce(t1.key, val=pw.reducers.sum(t2.value))\n\n# after (keys provably equal)\nt2_aligned = t2.with_universe_of(t1)\nres = t1.groupby(t1.key).reduce(t1.key, val=pw.reducers.sum(t2_aligned.value))","handlingStrategy":"validation","validationCode":"# before reduce, verify all referenced columns share the grouped table's universe\nuniv = table_to_group._universe\nfor col_expr in my_expressions:\n    assert col_expr._column.universe == univ or col_expr._column.universe.is_subset_of(univ), \"align universes with with_universe_of or join first\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all columns in a reduce on one table (join first) rather than mixing tables","Use with_universe_of only when key-set equality is a structural guarantee, not an assumption about data"],"tags":["pathway","groupby","universe","reduce","api-misuse"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}