Set new ids based on another column containing id-typed values. To generate ids based on arbitrary valued columns, use `with_id_from`. Values assigned must be row-wise unique. The uniqueness is not checked by pathway. Failing to provide unique ids can cause unexpect
(self, new_index: expr.ColumnReference)
| 1897 | @desugar |
| 1898 | @check_arg_types |
| 1899 | def with_id(self, new_index: expr.ColumnReference) -> Table: |
| 1900 | """Set new ids based on another column containing id-typed values. |
| 1901 | |
| 1902 | To generate ids based on arbitrary valued columns, use `with_id_from`. |
| 1903 | |
| 1904 | Values assigned must be row-wise unique. |
| 1905 | The uniqueness is not checked by pathway. Failing to provide unique ids can |
| 1906 | cause unexpected errors downstream. |
| 1907 | |
| 1908 | Args: |
| 1909 | new_id: column to be used as the new index. |
| 1910 | |
| 1911 | Returns: |
| 1912 | Table with updated ids. |
| 1913 | |
| 1914 | Example: |
| 1915 | |
| 1916 | >>> import pytest; pytest.xfail("with_id is hard to test") |
| 1917 | >>> import pathway as pw |
| 1918 | >>> t1 = pw.debug.table_from_markdown(''' |
| 1919 | ... | age | owner | pet |
| 1920 | ... 1 | 10 | Alice | 1 |
| 1921 | ... 2 | 9 | Bob | 1 |
| 1922 | ... 3 | 8 | Alice | 2 |
| 1923 | ... ''') |
| 1924 | >>> t2 = pw.debug.table_from_markdown(''' |
| 1925 | ... | new_id |
| 1926 | ... 1 | 2 |
| 1927 | ... 2 | 3 |
| 1928 | ... 3 | 4 |
| 1929 | ... ''') |
| 1930 | >>> t3 = t1.promise_universe_is_subset_of(t2).with_id(t2.new_id) |
| 1931 | >>> pw.debug.compute_and_print(t3) |
| 1932 | age owner pet |
| 1933 | ^2 10 Alice 1 |
| 1934 | ^3 9 Bob 1 |
| 1935 | ^4 8 Alice 2 |
| 1936 | """ |
| 1937 | return self._with_new_index(new_index) |
| 1938 | |
| 1939 | @trace_user_frame |
| 1940 | @desugar |