Changesets · Branches · Tags · Compare
| Changeset | fb6326207146bcccdd24daceb1fd67a111fb595bf46f01e4a64331343f9e7c50 |
|---|---|
| Author | Gagan Bhullar <g.deepsingh1@gmail.com> · 2024-10-08 20:41 -06:00 |
| Committer | GitHub <noreply@github.com> · 2024-10-08 20:41 -06:00 |
| Parents | 60fbe9d6df68 |
4 files changed
modified python/python/lancedb/common.py +1 −1
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | |
| 21 | 21 | pd = safe_import_pandas() |
| 22 | 22 | |
| 23 | -DATA = Union[List[dict], dict, "pd.DataFrame", pa.Table, Iterable[pa.RecordBatch]] | |
| 23 | +DATA = Union[List[dict], "pd.DataFrame", pa.Table, Iterable[pa.RecordBatch]] | |
| 24 | 24 | VEC = Union[list, np.ndarray, pa.Array, pa.ChunkedArray] |
| 25 | 25 | URI = Union[str, Path] |
| 26 | 26 | VECTOR_COLUMN_NAME = "vector" |
modified python/python/lancedb/db.py +2 −2
| @@ -96,7 +96,7 @@ | ||
| 96 | 96 | User must provide at least one of `data` or `schema`. |
| 97 | 97 | Acceptable types are: |
| 98 | 98 | |
| 99 | - - dict or list-of-dict | |
| 99 | + - list-of-dict | |
| 100 | 100 | |
| 101 | 101 | - pandas.DataFrame |
| 102 | 102 | |
| @@ -579,7 +579,7 @@ | ||
| 579 | 579 | User must provide at least one of `data` or `schema`. |
| 580 | 580 | Acceptable types are: |
| 581 | 581 | |
| 582 | - - dict or list-of-dict | |
| 582 | + - list-of-dict | |
| 583 | 583 | |
| 584 | 584 | - pandas.DataFrame |
| 585 | 585 |
modified python/python/lancedb/table.py +6 −6
| @@ -31,7 +31,6 @@ | ||
| 31 | 31 | import pyarrow.fs as pa_fs |
| 32 | 32 | from lance import LanceDataset |
| 33 | 33 | from lance.dependencies import _check_for_hugging_face |
| 34 | -from lance.vector import vec_to_table | |
| 35 | 34 | |
| 36 | 35 | from .common import DATA, VEC, VECTOR_COLUMN_NAME |
| 37 | 36 | from .embeddings import EmbeddingFunctionConfig, EmbeddingFunctionRegistry |
| @@ -87,6 +86,9 @@ | ||
| 87 | 86 | if isinstance(data, LanceModel): |
| 88 | 87 | raise ValueError("Cannot add a single LanceModel to a table. Use a list.") |
| 89 | 88 | |
| 89 | + if isinstance(data, dict): | |
| 90 | + raise ValueError("Cannot add a single dictionary to a table. Use a list.") | |
| 91 | + | |
| 90 | 92 | if isinstance(data, list): |
| 91 | 93 | # convert to list of dict if data is a bunch of LanceModels |
| 92 | 94 | if isinstance(data[0], LanceModel): |
| @@ -98,8 +100,6 @@ | ||
| 98 | 100 | return pa.Table.from_batches(data, schema=schema) |
| 99 | 101 | else: |
| 100 | 102 | return pa.Table.from_pylist(data) |
| 101 | - elif isinstance(data, dict): | |
| 102 | - return vec_to_table(data) | |
| 103 | 103 | elif _check_for_pandas(data) and isinstance(data, pd.DataFrame): |
| 104 | 104 | # Do not add schema here, since schema may contains the vector column |
| 105 | 105 | table = pa.Table.from_pandas(data, preserve_index=False) |
| @@ -554,7 +554,7 @@ | ||
| 554 | 554 | data: DATA |
| 555 | 555 | The data to insert into the table. Acceptable types are: |
| 556 | 556 | |
| 557 | - - dict or list-of-dict | |
| 557 | + - list-of-dict | |
| 558 | 558 | |
| 559 | 559 | - pandas.DataFrame |
| 560 | 560 | |
| @@ -1409,7 +1409,7 @@ | ||
| 1409 | 1409 | |
| 1410 | 1410 | Parameters |
| 1411 | 1411 | ---------- |
| 1412 | - data: list-of-dict, dict, pd.DataFrame | |
| 1412 | + data: list-of-dict, pd.DataFrame | |
| 1413 | 1413 | The data to insert into the table. |
| 1414 | 1414 | mode: str |
| 1415 | 1415 | The mode to use when writing the data. Valid values are |
| @@ -2348,7 +2348,7 @@ | ||
| 2348 | 2348 | data: DATA |
| 2349 | 2349 | The data to insert into the table. Acceptable types are: |
| 2350 | 2350 | |
| 2351 | - - dict or list-of-dict | |
| 2351 | + - list-of-dict | |
| 2352 | 2352 | |
| 2353 | 2353 | - pandas.DataFrame |
| 2354 | 2354 |
modified python/python/tests/test_table.py +18 −0
| @@ -193,6 +193,24 @@ | ||
| 193 | 193 | tbl.add(data=data) |
| 194 | 194 | |
| 195 | 195 | |
| 196 | +def test_add_dictionary(db): | |
| 197 | + schema = pa.schema( | |
| 198 | + [ | |
| 199 | + pa.field("vector", pa.list_(pa.float32(), 2)), | |
| 200 | + pa.field("item", pa.string()), | |
| 201 | + pa.field("price", pa.float32()), | |
| 202 | + ] | |
| 203 | + ) | |
| 204 | + tbl = LanceTable.create(db, "test", schema=schema) | |
| 205 | + data = {"vector": [3.1, 4.1], "item": "foo", "price": 10.0} | |
| 206 | + with pytest.raises(ValueError) as excep_info: | |
| 207 | + tbl.add(data=data) | |
| 208 | + assert ( | |
| 209 | + str(excep_info.value) | |
| 210 | + == "Cannot add a single dictionary to a table. Use a list." | |
| 211 | + ) | |
| 212 | + | |
| 213 | + | |
| 196 | 214 | def test_add(db): |
| 197 | 215 | schema = pa.schema( |
| 198 | 216 | [ |