MCPcopy Index your code
hub / github.com/pathwaycom/pathway / intersect

Method intersect

python/pathway/internals/table.py:1025–1071  ·  view source on GitHub ↗

Restrict self universe to keys appearing in all of the tables. Args: tables: tables keys of which are used to restrict universe. Returns: Table: table with restricted universe, with the same set of columns Example: >>> import pathway as pw

(self, *tables: Table)

Source from the content-addressed store, hash-verified

1023
1024 @check_arg_types
1025 def intersect(self, *tables: Table) -> Table[TSchema]:
1026 """Restrict self universe to keys appearing in all of the tables.
1027
1028 Args:
1029 tables: tables keys of which are used to restrict universe.
1030
1031 Returns:
1032 Table: table with restricted universe, with the same set of columns
1033
1034
1035 Example:
1036
1037 >>> import pathway as pw
1038 >>> t1 = pw.debug.table_from_markdown('''
1039 ... | age | owner | pet
1040 ... 1 | 10 | Alice | 1
1041 ... 2 | 9 | Bob | 1
1042 ... 3 | 8 | Alice | 2
1043 ... ''')
1044 >>> t2 = pw.debug.table_from_markdown('''
1045 ... | cost
1046 ... 2 | 100
1047 ... 3 | 200
1048 ... 4 | 300
1049 ... ''')
1050 >>> t3 = t1.intersect(t2)
1051 >>> pw.debug.compute_and_print(t3, include_id=False)
1052 age | owner | pet
1053 8 | Alice | 2
1054 9 | Bob | 1
1055 """
1056 if len(tables) == 0:
1057 warnings.warn("Empty argument list for Table.intersect().", stacklevel=5)
1058 return self
1059 all_args: list[Table] = [self, *tables]
1060 intersecting_universes = [tab._universe for tab in all_args]
1061 universe = self._get_universe_solver().get_intersection(*intersecting_universes)
1062 if universe.is_equal_to(self._universe):
1063 warnings.warn("Unnecessary call to Table.intersect().", stacklevel=5)
1064 for tab in tables:
1065 if universe.is_equal_to(tab._universe):
1066 warnings.warn(
1067 "Table.intersect() can be replaced with Table.restrict() operation.",
1068 stacklevel=5,
1069 )
1070 break
1071 return self._intersect(*tables)
1072
1073 @contextualized_operator
1074 def _intersect(self, *tables: Table) -> Table[TSchema]:

Callers 15

_intersectFunction · 0.80
test_intersectFunction · 0.80
test_intersect_emptyFunction · 0.80
test_intersect_subsetFunction · 0.80
test_multiple_ixFunction · 0.80
logicFunction · 0.80
test_intersectFunction · 0.80
test_intersect_2Function · 0.80
TFunction · 0.80
index-BCRWi5Lr.jsFile · 0.80

Calls 4

_get_universe_solverMethod · 0.95
_intersectMethod · 0.95
get_intersectionMethod · 0.80
is_equal_toMethod · 0.80

Tested by 9

test_intersectFunction · 0.64
test_intersect_emptyFunction · 0.64
test_intersect_subsetFunction · 0.64
test_multiple_ixFunction · 0.64
logicFunction · 0.64
test_intersectFunction · 0.64
test_intersect_2Function · 0.64