Updates cells of `self`, breaking ties in favor of the values in `other`. Semantics: - result.columns == self.columns - result.id == self.id - conflicts are resolved preferring other's values Requires: - other.columns ⊆ self.columns
(self, other: Table, _stacklevel: int = 1)
| 1689 | @trace_user_frame |
| 1690 | @check_arg_types |
| 1691 | def update_cells(self, other: Table, _stacklevel: int = 1) -> Table: |
| 1692 | """Updates cells of `self`, breaking ties in favor of the values in `other`. |
| 1693 | |
| 1694 | Semantics: |
| 1695 | - result.columns == self.columns |
| 1696 | - result.id == self.id |
| 1697 | - conflicts are resolved preferring other's values |
| 1698 | |
| 1699 | Requires: |
| 1700 | - other.columns ⊆ self.columns |
| 1701 | - other.id ⊆ self.id |
| 1702 | |
| 1703 | Args: |
| 1704 | other: the other table. |
| 1705 | |
| 1706 | Returns: |
| 1707 | Table: `self` updated with cells form `other`. |
| 1708 | |
| 1709 | Example: |
| 1710 | |
| 1711 | >>> import pathway as pw |
| 1712 | >>> t1 = pw.debug.table_from_markdown(''' |
| 1713 | ... | age | owner | pet |
| 1714 | ... 1 | 10 | Alice | 1 |
| 1715 | ... 2 | 9 | Bob | 1 |
| 1716 | ... 3 | 8 | Alice | 2 |
| 1717 | ... ''') |
| 1718 | >>> t2 = pw.debug.table_from_markdown(''' |
| 1719 | ... age | owner | pet |
| 1720 | ... 1 | 10 | Alice | 30 |
| 1721 | ... ''') |
| 1722 | >>> pw.universes.promise_is_subset_of(t2, t1) |
| 1723 | >>> t3 = t1.update_cells(t2) |
| 1724 | >>> pw.debug.compute_and_print(t3, include_id=False) |
| 1725 | age | owner | pet |
| 1726 | 8 | Alice | 2 |
| 1727 | 9 | Bob | 1 |
| 1728 | 10 | Alice | 30 |
| 1729 | """ |
| 1730 | if names := (set(other.keys()) - set(self.keys())): |
| 1731 | raise ValueError( |
| 1732 | f"Columns of the argument in Table.update_cells() not present in the updated table: {list(names)}." |
| 1733 | ) |
| 1734 | |
| 1735 | if self._universe == other._universe: |
| 1736 | warnings.warn( |
| 1737 | "Key sets of self and other in update_cells are the same." |
| 1738 | + " Using with_columns instead of update_cells.", |
| 1739 | stacklevel=_stacklevel + 4, |
| 1740 | ) |
| 1741 | return self.with_columns(*(other[name] for name in other)) |
| 1742 | |
| 1743 | schema = {} |
| 1744 | for key in other.keys(): |
| 1745 | schema[key] = _types_lca_with_error( |
| 1746 | self.schema._dtypes()[key], |
| 1747 | other.schema._dtypes()[key], |
| 1748 | function_name="an update_cells", |