Skip to content

fix(util): convert numpy scalars in value_to_sql#3522

Merged
wjones127 merged 1 commit into
lancedb:mainfrom
devteamaegis:fix/value-to-sql-numpy-scalars-fork
Jun 9, 2026
Merged

fix(util): convert numpy scalars in value_to_sql#3522
wjones127 merged 1 commit into
lancedb:mainfrom
devteamaegis:fix/value-to-sql-numpy-scalars-fork

Conversation

@devteamaegis

Copy link
Copy Markdown
Contributor

What's broken

Table.update(values={...}) raises NotImplementedError: SQL conversion is not implemented for this type when a value is a numpy scalar such as np.int64, np.int32, np.float32, or np.bool_. These arise naturally from indexing an ndarray or a pandas int/bool column. np.float64 happens to work (it subclasses float), which makes the failure inconsistent and surprising.

df = pd.DataFrame({"id": np.array([10, 20], dtype="int32")})
t.update(where="id = 1", values={"id": df["id"].iloc[0]})   # np.int32
# -> NotImplementedError: SQL conversion is not implemented for this type

Why it happens

value_to_sql is a singledispatch with handlers only for native Python types and np.ndarray; numpy integer/floating/bool_ scalars aren't Python subclasses, so they fall through to the NotImplementedError base.

Fix

Register handlers for np.bool_, np.integer, and np.floating that delegate to the existing native handlers.

Test

value_to_sql on np.int32/int64/float32/float64/bool_ all convert; np.int32 raised before.

table.update() crashed with NotImplementedError when an update value was
a numpy scalar (e.g. np.int64, np.float32, np.bool_) such as one pulled
from an ndarray or a pandas integer column. np.float64 worked only because
it subclasses Python float, making the failure surprising and inconsistent.
Register np.integer, np.floating, and np.bool_ handlers that delegate to the
existing native-type handlers.
@github-actions github-actions Bot added bug Something isn't working Python Python SDK labels Jun 9, 2026

@wjones127 wjones127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@wjones127
wjones127 merged commit f260d3b into lancedb:main Jun 9, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Python Python SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants