docs: expose merge_insert doc for remote python SDK (#1464)

`merge_insert` API is not shown up on
[`RemoteTable`](https://lancedb.github.io/lancedb/python/saas-python/#lancedb.remote.table.RemoteTable)
today

* Also bump `ruff` version as well
This commit is contained in:
Lei Xu
2024-07-22 10:48:16 -07:00
committed by GitHub
parent 69295548cc
commit c9c61eb060
4 changed files with 29 additions and 21 deletions

View File

@@ -33,11 +33,11 @@ jobs:
python-version: "3.11" python-version: "3.11"
- name: Install ruff - name: Install ruff
run: | run: |
pip install ruff==0.2.2 pip install ruff==0.5.4
- name: Format check - name: Format check
run: ruff format --check . run: ruff format --check .
- name: Lint - name: Lint
run: ruff . run: ruff check .
doctest: doctest:
name: "Doctest" name: "Doctest"
timeout-minutes: 30 timeout-minutes: 30

View File

@@ -1,6 +1,6 @@
# Python API Reference (SaaS) # Python API Reference (SaaS)
This section contains the API reference for the SaaS Python API. This section contains the API reference for the LanceDB Cloud Python API.
## Installation ## Installation

View File

@@ -163,19 +163,19 @@ def _py_type_to_arrow_type(py_type: Type[Any], field: FieldInfo) -> pa.DataType:
TypeError TypeError
If the type is not supported. If the type is not supported.
""" """
if py_type == int: if py_type is int:
return pa.int64() return pa.int64()
elif py_type == float: elif py_type is float:
return pa.float64() return pa.float64()
elif py_type == str: elif py_type is str:
return pa.utf8() return pa.utf8()
elif py_type == bool: elif py_type is bool:
return pa.bool_() return pa.bool_()
elif py_type == bytes: elif py_type is bytes:
return pa.binary() return pa.binary()
elif py_type == date: elif py_type is date:
return pa.date32() return pa.date32()
elif py_type == datetime: elif py_type is datetime:
tz = get_extras(field, "tz") tz = get_extras(field, "tz")
return pa.timestamp("us", tz=tz) return pa.timestamp("us", tz=tz)
elif getattr(py_type, "__origin__", None) in (list, tuple): elif getattr(py_type, "__origin__", None) in (list, tuple):
@@ -210,17 +210,17 @@ def _pydantic_to_arrow_type(field: FieldInfo) -> pa.DataType:
): ):
origin = field.annotation.__origin__ origin = field.annotation.__origin__
args = field.annotation.__args__ args = field.annotation.__args__
if origin == list: if origin is list:
child = args[0] child = args[0]
return pa.list_(_py_type_to_arrow_type(child, field)) return pa.list_(_py_type_to_arrow_type(child, field))
elif origin == Union: elif origin == Union:
if len(args) == 2 and args[1] == type(None): if len(args) == 2 and args[1] is type(None):
return _py_type_to_arrow_type(args[0], field) return _py_type_to_arrow_type(args[0], field)
elif sys.version_info >= (3, 10) and isinstance(field.annotation, types.UnionType): elif sys.version_info >= (3, 10) and isinstance(field.annotation, types.UnionType):
args = field.annotation.__args__ args = field.annotation.__args__
if len(args) == 2: if len(args) == 2:
for typ in args: for typ in args:
if typ == type(None): if typ is type(None):
continue continue
return _py_type_to_arrow_type(typ, field) return _py_type_to_arrow_type(typ, field)
elif inspect.isclass(field.annotation): elif inspect.isclass(field.annotation):
@@ -239,12 +239,12 @@ def is_nullable(field: FieldInfo) -> bool:
origin = field.annotation.__origin__ origin = field.annotation.__origin__
args = field.annotation.__args__ args = field.annotation.__args__
if origin == Union: if origin == Union:
if len(args) == 2 and args[1] == type(None): if len(args) == 2 and args[1] is type(None):
return True return True
elif sys.version_info >= (3, 10) and isinstance(field.annotation, types.UnionType): elif sys.version_info >= (3, 10) and isinstance(field.annotation, types.UnionType):
args = field.annotation.__args__ args = field.annotation.__args__
for typ in args: for typ in args:
if typ == type(None): if typ is type(None):
return True return True
return False return False

View File

@@ -330,6 +330,14 @@ class RemoteTable(Table):
result = self._conn._client.query(self._name, query) result = self._conn._client.query(self._name, query)
return result.to_arrow().to_reader() return result.to_arrow().to_reader()
def merge_insert(self, on: Union[str, Iterable[str]]) -> LanceMergeInsertBuilder:
"""Returns a [`LanceMergeInsertBuilder`][lancedb.merge.LanceMergeInsertBuilder]
that can be used to create a "merge insert" operation.
See [`Table.merge_insert`][lancedb.table.Table.merge_insert] for more details.
"""
super().merge_insert(on)
def _do_merge( def _do_merge(
self, self,
merge: LanceMergeInsertBuilder, merge: LanceMergeInsertBuilder,
@@ -354,9 +362,9 @@ class RemoteTable(Table):
params["on"] = merge._on[0] params["on"] = merge._on[0]
params["when_matched_update_all"] = str(merge._when_matched_update_all).lower() params["when_matched_update_all"] = str(merge._when_matched_update_all).lower()
if merge._when_matched_update_all_condition is not None: if merge._when_matched_update_all_condition is not None:
params[ params["when_matched_update_all_filt"] = (
"when_matched_update_all_filt" merge._when_matched_update_all_condition
] = merge._when_matched_update_all_condition )
params["when_not_matched_insert_all"] = str( params["when_not_matched_insert_all"] = str(
merge._when_not_matched_insert_all merge._when_not_matched_insert_all
).lower() ).lower()
@@ -364,9 +372,9 @@ class RemoteTable(Table):
merge._when_not_matched_by_source_delete merge._when_not_matched_by_source_delete
).lower() ).lower()
if merge._when_not_matched_by_source_condition is not None: if merge._when_not_matched_by_source_condition is not None:
params[ params["when_not_matched_by_source_delete_filt"] = (
"when_not_matched_by_source_delete_filt" merge._when_not_matched_by_source_condition
] = merge._when_not_matched_by_source_condition )
self._conn._client.post( self._conn._client.post(
f"/v1/table/{self._name}/merge_insert/", f"/v1/table/{self._name}/merge_insert/",