From e38fc117ad0ef306b5572ea682dcea4b8a5f1861 Mon Sep 17 00:00:00 2001 From: Gatefixer <313497061+lancedb-gatefixer[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 04:26:01 +0000 Subject: [PATCH] test(python): cover arithmetic with distance projections --- python/python/tests/test_query.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/python/python/tests/test_query.py b/python/python/tests/test_query.py index 6840be052..a3c94e7e8 100644 --- a/python/python/tests/test_query.py +++ b/python/python/tests/test_query.py @@ -666,6 +666,27 @@ def test_distance_range(table: lancedb.table.Table): assert res["_distance"].to_pylist() == [min_dist, max_dist] +@pytest.mark.parametrize( + ("expression", "expected_type"), + [ + ("1 - _distance", pa.float32()), + ("1.0 - _distance", pa.float64()), + ], +) +def test_select_arithmetic_with_distance(table, expression, expected_type): + result = ( + table.search([10, 10]) + .select({"similarity": expression}) + .distance_type("cosine") + .to_arrow() + ) + + assert result.schema.field("similarity").type == expected_type + assert result["similarity"].to_pylist() == pytest.approx( + [1 - distance for distance in result["_distance"].to_pylist()] + ) + + @pytest.mark.asyncio async def test_distance_range_async(table_async: AsyncTable): q = [0, 0]