lance.LanceDataset.update(updates: dict[str, str], where: str | None = None) UpdateResult

Update column values for rows matching where.

Parameters:
updates : dict of str to str

A mapping of column names to a SQL expression.

where : str, optional

A SQL predicate indicating which rows should be updated.

Returns:

updates – A dictionary containing the number of rows updated.

Return type:

dict

Examples

>>> import lance
>>> import pyarrow as pa
>>> table = pa.table({"a": [1, 2, 3], "b": ["a", "b", "c"]})
>>> dataset = lance.write_dataset(table, "example")
>>> update_stats = dataset.update(dict(a = 'a + 2'), where="b != 'a'")
>>> update_stats["num_updated_rows"] = 2
>>> dataset.to_table().to_pandas()
   a  b
0  1  a
1  4  b
2  5  c