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

Method with_id

python/pathway/internals/table.py:1899–1937  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

_apply_rerankingMethod · 0.80
_pandas_transformerFunction · 0.80
multiapply_all_rowsFunction · 0.80
argmax_rowsFunction · 0.80
argmin_rowsFunction · 0.80
add_update_timestamp_utcFunction · 0.80
_get_unmatched_rowsMethod · 0.80
_joinMethod · 0.80
queryMethod · 0.80
_contractFunction · 0.80
_contract_weightedFunction · 0.80
_propose_clustersFunction · 0.80

Calls 1

_with_new_indexMethod · 0.95

Tested by 6

test_aknnFunction · 0.64
test_reindexFunction · 0.64
test_reindex_no_columnsFunction · 0.64
test_clustering_qualityFunction · 0.64