From cca6a7c989d4e951485c64766175abe30eb2ba9a Mon Sep 17 00:00:00 2001 From: Dan Tasse <105866+dantasse@users.noreply.github.com> Date: Wed, 25 Mar 2026 21:49:29 -0400 Subject: [PATCH] fix: raise instead of return ValueError (#3189) These couple of cases used to return ValueError; should raise it instead. --- python/python/lancedb/query.py | 4 ++-- python/python/tests/test_query.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/python/python/lancedb/query.py b/python/python/lancedb/query.py index 66ff03a4a..8561f68de 100644 --- a/python/python/lancedb/query.py +++ b/python/python/lancedb/query.py @@ -70,7 +70,7 @@ def ensure_vector_query( ) -> Union[List[float], List[List[float]], pa.Array, List[pa.Array]]: if isinstance(val, list): if len(val) == 0: - return ValueError("Vector query must be a non-empty list") + raise ValueError("Vector query must be a non-empty list") sample = val[0] else: if isinstance(val, float): @@ -83,7 +83,7 @@ def ensure_vector_query( return val if isinstance(sample, list): if len(sample) == 0: - return ValueError("Vector query must be a non-empty list") + raise ValueError("Vector query must be a non-empty list") if isinstance(sample[0], float): # val is list of list of floats return val diff --git a/python/python/tests/test_query.py b/python/python/tests/test_query.py index 2105a4dfa..a7153b010 100644 --- a/python/python/tests/test_query.py +++ b/python/python/tests/test_query.py @@ -30,6 +30,7 @@ from lancedb.query import ( PhraseQuery, Query, FullTextSearchQuery, + ensure_vector_query, ) from lancedb.rerankers.cross_encoder import CrossEncoderReranker from lancedb.table import AsyncTable, LanceTable @@ -1501,6 +1502,18 @@ def test_search_empty_table(mem_db): assert results == [] +def test_ensure_vector_query_empty_list(): + """Regression: ensure_vector_query used to return instead of raise ValueError.""" + with pytest.raises(ValueError, match="non-empty"): + ensure_vector_query([]) + + +def test_ensure_vector_query_nested_empty_list(): + """Regression: ensure_vector_query used to return instead of raise ValueError.""" + with pytest.raises(ValueError, match="non-empty"): + ensure_vector_query([[]]) + + def test_fast_search(tmp_path): db = lancedb.connect(tmp_path)