Updates rows of `self`, breaking ties in favor for the rows in `other`. Semantics: - result.columns == self.columns == other.columns - result.id == self.id ∪ other.id Requires: - other.columns == self.columns Args: other: the other tabl
(self, other: Table[TSchema])
| 1774 | @trace_user_frame |
| 1775 | @check_arg_types |
| 1776 | def update_rows(self, other: Table[TSchema]) -> Table[TSchema]: |
| 1777 | """Updates rows of `self`, breaking ties in favor for the rows in `other`. |
| 1778 | |
| 1779 | Semantics: |
| 1780 | - result.columns == self.columns == other.columns |
| 1781 | - result.id == self.id ∪ other.id |
| 1782 | |
| 1783 | Requires: |
| 1784 | - other.columns == self.columns |
| 1785 | |
| 1786 | Args: |
| 1787 | other: the other table. |
| 1788 | |
| 1789 | Returns: |
| 1790 | Table: `self` updated with rows form `other`. |
| 1791 | |
| 1792 | Example: |
| 1793 | |
| 1794 | >>> import pathway as pw |
| 1795 | >>> t1 = pw.debug.table_from_markdown(''' |
| 1796 | ... | age | owner | pet |
| 1797 | ... 1 | 10 | Alice | 1 |
| 1798 | ... 2 | 9 | Bob | 1 |
| 1799 | ... 3 | 8 | Alice | 2 |
| 1800 | ... ''') |
| 1801 | >>> t2 = pw.debug.table_from_markdown(''' |
| 1802 | ... | age | owner | pet |
| 1803 | ... 1 | 10 | Alice | 30 |
| 1804 | ... 12 | 12 | Tom | 40 |
| 1805 | ... ''') |
| 1806 | >>> t3 = t1.update_rows(t2) |
| 1807 | >>> pw.debug.compute_and_print(t3, include_id=False) |
| 1808 | age | owner | pet |
| 1809 | 8 | Alice | 2 |
| 1810 | 9 | Bob | 1 |
| 1811 | 10 | Alice | 30 |
| 1812 | 12 | Tom | 40 |
| 1813 | """ |
| 1814 | if other.keys() != self.keys(): |
| 1815 | raise ValueError( |
| 1816 | "Columns do not match between argument of Table.update_rows() and the updated table." |
| 1817 | ) |
| 1818 | if self._universe.is_subset_of(other._universe): |
| 1819 | warnings.warn( |
| 1820 | "Universe of self is a subset of universe of other in update_rows. Returning other.", |
| 1821 | stacklevel=5, |
| 1822 | ) |
| 1823 | return other |
| 1824 | |
| 1825 | schema = {} |
| 1826 | |
| 1827 | for key in self.keys(): |
| 1828 | schema[key] = _types_lca_with_error( |
| 1829 | self.schema._dtypes()[key], |
| 1830 | other.schema._dtypes()[key], |
| 1831 | function_name="an update_rows", |
| 1832 | pointers=False, |
| 1833 | ) |