From be19a880a969ebd0a252bdac49ce5e3b9670b474 Mon Sep 17 00:00:00 2001 From: Jack Ye Date: Sat, 11 Apr 2026 22:48:23 -0700 Subject: [PATCH] fix: format, lint, and update tests for namespace delegation - Run ruff format on all changed files - Fix F821 forward reference in _namespace_conn return type - Update test_local_namespace_operations to verify operations succeed instead of expecting NotImplementedError (namespace ops now work on LanceDBConnection via directory namespace delegation) - Remove test_local_create_namespace_not_supported and test_local_drop_namespace_not_supported (no longer applicable) Co-Authored-By: Claude Opus 4.6 (1M context) --- python/python/lancedb/__init__.py | 2 +- python/python/lancedb/db.py | 28 +++++++++----------- python/python/lancedb/namespace.py | 26 +++++++++--------- python/python/tests/test_db.py | 42 ++++++++---------------------- 4 files changed, 39 insertions(+), 59 deletions(-) diff --git a/python/python/lancedb/__init__.py b/python/python/lancedb/__init__.py index 79a6428c4..df796fdd9 100644 --- a/python/python/lancedb/__init__.py +++ b/python/python/lancedb/__init__.py @@ -232,7 +232,7 @@ def _apply_worker_overrides(props: dict[str, str]) -> dict[str, str]: result = dict(props) for key in worker_keys: value = result.pop(key) - real_key = key[len(WORKER_PROPERTY_PREFIX):] + real_key = key[len(WORKER_PROPERTY_PREFIX) :] result[real_key] = value return result diff --git a/python/python/lancedb/db.py b/python/python/lancedb/db.py index cabf5e50c..d586ebc93 100644 --- a/python/python/lancedb/db.py +++ b/python/python/lancedb/db.py @@ -540,9 +540,7 @@ class DBConnection(EnforceOverrides): str Serialized representation of this connection. """ - raise NotImplementedError( - "serialize is not supported for this connection type" - ) + raise NotImplementedError("serialize is not supported for this connection type") class LanceDBConnection(DBConnection): @@ -674,14 +672,16 @@ class LanceDBConnection(DBConnection): import json rci = self.read_consistency_interval - return json.dumps({ - "connection_type": "local", - "uri": self.uri, - "storage_options": self.storage_options, - "read_consistency_interval_seconds": ( - rci.total_seconds() if rci else None - ), - }) + return json.dumps( + { + "connection_type": "local", + "uri": self.uri, + "storage_options": self.storage_options, + "read_consistency_interval_seconds": ( + rci.total_seconds() if rci else None + ), + } + ) async def _async_get_table_names(self, start_after: Optional[str], limit: int): conn = AsyncConnection(await lancedb_connect(self.uri)) @@ -918,7 +918,7 @@ class LanceDBConnection(DBConnection): ) return tbl - def _namespace_conn(self) -> "LanceNamespaceDBConnection": + def _namespace_conn(self) -> DBConnection: """Return a LanceNamespaceDBConnection backed by this connection's directory namespace. Used to delegate child-namespace operations.""" from lancedb.namespace import LanceNamespaceDBConnection @@ -1122,9 +1122,7 @@ class LanceDBConnection(DBConnection): The namespace client for this connection. """ if self._cached_namespace_client is None: - self._cached_namespace_client = LOOP.run( - self._conn.namespace_client() - ) + self._cached_namespace_client = LOOP.run(self._conn.namespace_client()) return self._cached_namespace_client @deprecation.deprecated( diff --git a/python/python/lancedb/namespace.py b/python/python/lancedb/namespace.py index 0cc83af31..58e1e011a 100644 --- a/python/python/lancedb/namespace.py +++ b/python/python/lancedb/namespace.py @@ -427,18 +427,20 @@ class LanceNamespaceDBConnection(DBConnection): def serialize(self) -> str: import json - return json.dumps({ - "connection_type": "namespace", - "namespace_client_impl": self._namespace_client_impl, - "namespace_client_properties": self._namespace_client_properties, - "pushdown_operations": sorted(self._pushdown_operations), - "storage_options": self.storage_options or None, - "read_consistency_interval_seconds": ( - self.read_consistency_interval.total_seconds() - if self.read_consistency_interval - else None - ), - }) + return json.dumps( + { + "connection_type": "namespace", + "namespace_client_impl": self._namespace_client_impl, + "namespace_client_properties": self._namespace_client_properties, + "pushdown_operations": sorted(self._pushdown_operations), + "storage_options": self.storage_options or None, + "read_consistency_interval_seconds": ( + self.read_consistency_interval.total_seconds() + if self.read_consistency_interval + else None + ), + } + ) @override def table_names( diff --git a/python/python/tests/test_db.py b/python/python/tests/test_db.py index ebb42b61e..5f3fc60ec 100644 --- a/python/python/tests/test_db.py +++ b/python/python/tests/test_db.py @@ -897,42 +897,22 @@ def test_bypass_vector_index_sync(tmp_db: lancedb.DBConnection): def test_local_namespace_operations(tmp_path): - """Test that local mode namespace operations behave as expected.""" - # Create a local database connection + """Test that local mode namespace operations work via directory namespace.""" db = lancedb.connect(tmp_path) - # Test list_namespaces returns empty list for root namespace - namespaces = db.list_namespaces().namespaces - assert namespaces == [] + # Root namespace starts empty + assert db.list_namespaces().namespaces == [] - # Test list_namespaces with non-empty namespace raises NotImplementedError - with pytest.raises( - NotImplementedError, - match="Namespace operations are not supported for listing database", - ): - db.list_namespaces(namespace_path=["test"]) + # Create and list child namespace + db.create_namespace(["child"]) + assert "child" in db.list_namespaces().namespaces + # List namespaces under child + assert db.list_namespaces(namespace_path=["child"]).namespaces == [] -def test_local_create_namespace_not_supported(tmp_path): - """Test that create_namespace is not supported in local mode.""" - db = lancedb.connect(tmp_path) - - with pytest.raises( - NotImplementedError, - match="Namespace operations are not supported for listing database", - ): - db.create_namespace(["test_namespace"]) - - -def test_local_drop_namespace_not_supported(tmp_path): - """Test that drop_namespace is not supported in local mode.""" - db = lancedb.connect(tmp_path) - - with pytest.raises( - NotImplementedError, - match="Namespace operations are not supported for listing database", - ): - db.drop_namespace(["test_namespace"]) + # Drop namespace + db.drop_namespace(["child"]) + assert db.list_namespaces().namespaces == [] def test_clone_table_latest_version(tmp_path):