Skip to content

bug(python): LanceError(IO) when using arithmetic SQL expressions #2618

Closed

Description

@mykolaskrynnyk

LanceDB version

v0.24.3

What happened?

Using dynamic SQL expressions in select method raises LanceError(IO) for arithmetic operations involving mixed numeric types.

Are there known steps to reproduce?

Here is a simple example:

import lancedb

uri = "data/sample-lancedb"
db = lancedb.connect(uri)

data = [
    {"vector": [3.1, 4.1], "item": "foo"},
    {"vector": [5.9, 26.5], "item": "bar"},
]

tbl = db.create_table("my_table", data=data)

tbl.search([10, 10]).select({"similarity": "1 - _distance"}).distance_type("cosine").to_list()

This used to work without any issues in v0.23.0. In v0.24.3, however, it raises:

RuntimeError: lance error: LanceError(IO): Arrow error: Invalid argument error: Invalid arithmetic operation: Int64 - Float32, /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/lance-0.33.0/src/dataset/scanner.rs:3415:83

This won't work either:

tbl.search([10, 10]).distance_type("cosine").select({"similarity": "1.0 - _distance"}).to_list()
# RuntimeError: lance error: LanceError(IO): Arrow error: Invalid argument error: Invalid arithmetic operation: Float64 - Float32, /Users/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/lance-0.33.0/src/dataset/scanner.rs:3415:83

One now needs to cast to float explicitly:

tbl.search([10, 10]).distance_type("cosine").select({"similarity": "1::float - _distance"}).to_list()
# [{'similarity': 0.9904922842979431, '_distance': 0.009507715702056885},
#  {'similarity': 0.8438758850097656, '_distance': 0.15612411499023438}]

I guess something has changed in how dtypes are promoted as 1, 1.0 and _distance were treated as Int64, Float64 and Float32 respectively in previous versions too, but no error was raised.

Activity

  1. added
    bug
    on Aug 28, 2025
  2. jbapple commented on Aug 29, 2025

    @jbapple

    Hm, I don't see anything in the history in https://github.com/lancedb/lance/commits/main/python/src/scanner.rs that looks related. Maybe an Arrow change? I'll find someone to take a look.

  3. wjones127 commented on Sep 12, 2025

    @wjones127
    Contributor

    Thanks for reporting this. I've made an issue upstream where we will fix this: lance-format/lance#4712

    It seems to be isolated to calculations involving the _distance column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions