{"record":{"id":"d8936520d4d0d45c","repo":"pathwaycom/pathway","slug":"table-restrict-other-universe-has-to-be-a-subse","errorCode":null,"errorMessage":"Table.restrict(): other universe has to be a subset of self universe.Consider using Table.promise_universe_is_subset_of() to assert it.","messagePattern":"Table\\.restrict\\(\\): other universe has to be a subset of self universe\\.Consider using Table\\.promise_universe_is_subset_of\\(\\) to assert it\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/table.py","lineNumber":1127,"sourceCode":"        ...     '''\n        ...   | cost\n        ... 2 | 100\n        ... 3 | 200\n        ... '''\n        ... )\n        >>> t2.promise_universe_is_subset_of(t1)\n        <pathway.Table schema={'cost': <class 'int'>}>\n        >>> t3 = t1.restrict(t2)\n        >>> pw.debug.compute_and_print(t3, include_id=False)\n        age | owner | pet\n        8   | Alice | 2\n        9   | Bob   | 1\n        \"\"\"\n        if self._universe == other._universe:\n            warnings.warn(\"Identical universes for Table.restrict().\", stacklevel=5)\n            return self\n        if not other._universe.is_subset_of(self._universe):\n            raise ValueError(\n                \"Table.restrict(): other universe has to be a subset of self universe.\"\n                + \"Consider using Table.promise_universe_is_subset_of() to assert it.\"\n            )\n        if other._universe.is_equal_to(self._universe):\n            warnings.warn(\n                \"Unnecessary call to Table.restrict(), consider using Table.with_universe_of().\",\n                stacklevel=5,\n            )\n        return self._restrict(other)\n\n    @contextualized_operator\n    def _restrict(self, other: TableLike) -> Table[TSchema]:\n        context = clmn.RestrictContext(self._id_column, other._id_column)\n\n        columns = {\n            name: self._wrap_column_in_context(context, column, name)\n            for name, column in self._columns.items()\n        }","sourceCodeStart":1109,"sourceCodeEnd":1145,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/table.py#L1109-L1145","documentation":"Table.restrict(other) keeps only rows of self whose ids appear in other's universe, so other must be a subset. After a fast-path for identical universes (warning + return self), it verifies other._universe.is_subset_of(self._universe) and raises ValueError otherwise, suggesting Table.promise_universe_is_subset_of() to assert the relation when the check is too strict/expensive.","triggerScenarios":"t1.restrict(t2) where t2 contains ids not present in t1 — e.g. t2 came from a different source, was reindexed (concat_reindex / new ids), or an outer-join result restricted against an inner table.","commonSituations":"Restricting a large table by a set computed from another connector; ids regenerated by an intermediate operation; graph/rewrite pipelines where universes drift.","solutions":["Rebuild other from self's universe: derive t2 via operations on t1, or apply t2 = t2.with_universe_of(t1)-style alignment appropriate to your data","If you are certain the subset relation holds (e.g. ids come from the same source), assert it: pw.Table.promise_universe_is_subset_of(t2, t1) before restrict","Debug by intersecting: check a few ids from t2 against t1 to find where the universes diverge"],"exampleFix":"# before\nt3 = t1.restrict(t2)  # t2 not a subset of t1 -> ValueError\n\n# after\npw.Table.promise_universe_is_subset_of(t2, t1)\nt3 = t1.restrict(t2)","handlingStrategy":"validation","validationCode":"def is_subset(small, big) -> bool:\n    return small._universe.is_subset_of(big._universe)","typeGuard":"import pathway as pw\n\ndef restrictable(sub: pw.Table, sup: pw.Table) -> bool:\n    return sub._universe.is_subset_of(sup._universe)","tryCatchPattern":null,"preventionTips":["Derive the restricting table from the same source to guarantee the subset relation","Use pw.Table.promise_universe_is_subset_of only when the relation is certain"],"tags":["universe","restrict","pathway"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}