Concats `self` with every `other` ∊ `others`. Semantics: - result.columns == self.columns == other.columns - result.id == self.id ∪ other.id if self.id and other.id collide, throws an exception. Requires: - other.columns == self.columns - se
(self, *others: Table[TSchema])
| 1584 | @trace_user_frame |
| 1585 | @check_arg_types |
| 1586 | def concat(self, *others: Table[TSchema]) -> Table[TSchema]: |
| 1587 | """Concats `self` with every `other` ∊ `others`. |
| 1588 | |
| 1589 | Semantics: |
| 1590 | - result.columns == self.columns == other.columns |
| 1591 | - result.id == self.id ∪ other.id |
| 1592 | |
| 1593 | if self.id and other.id collide, throws an exception. |
| 1594 | |
| 1595 | Requires: |
| 1596 | - other.columns == self.columns |
| 1597 | - self.id disjoint with other.id |
| 1598 | |
| 1599 | Args: |
| 1600 | other: the other table. |
| 1601 | |
| 1602 | Returns: |
| 1603 | Table: The concatenated table. Id's of rows from original tables are preserved. |
| 1604 | |
| 1605 | Example: |
| 1606 | |
| 1607 | >>> import pathway as pw |
| 1608 | >>> t1 = pw.debug.table_from_markdown(''' |
| 1609 | ... | age | owner | pet |
| 1610 | ... 1 | 10 | Alice | 1 |
| 1611 | ... 2 | 9 | Bob | 1 |
| 1612 | ... 3 | 8 | Alice | 2 |
| 1613 | ... ''') |
| 1614 | >>> t2 = pw.debug.table_from_markdown(''' |
| 1615 | ... | age | owner | pet |
| 1616 | ... 11 | 11 | Alice | 30 |
| 1617 | ... 12 | 12 | Tom | 40 |
| 1618 | ... ''') |
| 1619 | >>> pw.universes.promise_are_pairwise_disjoint(t1, t2) |
| 1620 | >>> t3 = t1.concat(t2) |
| 1621 | >>> pw.debug.compute_and_print(t3, include_id=False) |
| 1622 | age | owner | pet |
| 1623 | 8 | Alice | 2 |
| 1624 | 9 | Bob | 1 |
| 1625 | 10 | Alice | 1 |
| 1626 | 11 | Alice | 30 |
| 1627 | 12 | Tom | 40 |
| 1628 | """ |
| 1629 | for other in others: |
| 1630 | if other.keys() != self.keys(): |
| 1631 | self_keys = set(self.keys()) |
| 1632 | other_keys = set(other.keys()) |
| 1633 | missing_keys = self_keys - other_keys |
| 1634 | superfluous_keys = other_keys - self_keys |
| 1635 | raise ValueError( |
| 1636 | "columns do not match in the argument of Table.concat()." |
| 1637 | + ( |
| 1638 | f" Missing columns: {missing_keys}." |
| 1639 | if missing_keys is not None |
| 1640 | else "" |
| 1641 | ) |
| 1642 | + ( |
| 1643 | f" Superfluous columns: {superfluous_keys}." |