From e41894b0715f57d2773be83944ad9294e7a5b4b2 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Thu, 12 Oct 2023 00:50:46 +0530 Subject: [PATCH] [Docs] Improve visibility of table ops (#553) A little verbose, but better than being non-discoverable ![Screenshot from 2023-10-11 16-26-02](https://github.com/lancedb/lancedb/assets/15766192/9ba539a7-0cf8-4d9e-94e7-ce5d37c35df0) --- docs/mkdocs.yml | 5 +++-- docs/src/guides/tables.md | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 661ff602..780366d8 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -21,6 +21,7 @@ theme: - navigation.tracking - navigation.instant - navigation.indexes + - navigation.expand icon: repo: fontawesome/brands/github custom_dir: overrides @@ -68,7 +69,7 @@ nav: - 🏢 Home: index.md - 💡 Basics: basic.md - 📚 Guides: - - Tables: guides/tables.md + - Create Ingest Update Delete: guides/tables.md - Vector Search: search.md - SQL filters: sql.md - Indexing: ann_indexes.md @@ -100,7 +101,7 @@ nav: - Basics: basic.md - Guides: - - Tables: guides/tables.md + - Create Ingest Update Delete: guides/tables.md - Vector Search: search.md - SQL filters: sql.md - Indexing: ann_indexes.md diff --git a/docs/src/guides/tables.md b/docs/src/guides/tables.md index e3e9a35b..c75b333f 100644 --- a/docs/src/guides/tables.md +++ b/docs/src/guides/tables.md @@ -364,6 +364,48 @@ Use the `delete()` method on tables to delete rows from a table. To choose which await tbl.countRows() // Returns 1 ``` +### Updating a Table [Experimental] +EXPERIMENTAL: Update rows in the table (not threadsafe). + +This can be used to update zero to all rows depending on how many rows match the where clause. + +| Parameter | Type | Description | +|---|---|---| +| `where` | `str` | The SQL where clause to use when updating rows. For example, `'x = 2'` or `'x IN (1, 2, 3)'`. The filter must not be empty, or it will error. | +| `values` | `dict` | The values to update. The keys are the column names and the values are the values to set. | + + +=== "Python" + + ```python + import lancedb + import pandas as pd + + # Create a lancedb connection + db = lancedb.connect("./.lancedb") + + # Create a table from a pandas DataFrame + data = pd.DataFrame({"x": [1, 2, 3], "vector": [[1, 2], [3, 4], [5, 6]]}) + table = db.create_table("my_table", data) + + # Update the table where x = 2 + table.update(where="x = 2", values={"vector": [10, 10]}) + + # Get the updated table as a pandas DataFrame + df = table.to_pandas() + + # Print the DataFrame + print(df) + ``` + + Output + ```shell + x vector + 0 1 [1.0, 2.0] + 1 3 [5.0, 6.0] + 2 2 [10.0, 10.0] + ``` + ## What's Next? Learn how to Query your tables and create indices \ No newline at end of file