Skip to content

fix(projection): detect numpy and polars list columns as vectors - #271

Merged
donghaoren merged 1 commit into
apple:mainfrom
Yigtwxx:fix/infer-vector-modality
Oct 1, 2026
Merged

donghaoren merged 1 commit into
apple:mainfrom
Yigtwxx:fix/infer-vector-modality

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Problem

_infer_modality only calls a column "vector" when the first value is a Python list of int/float or an ndarray. Two common cases miss that and get treated as text:

A pandas column built like [list(v) for v in emb] from a float32 array holds np.float32 values, which aren't float subclasses. The vectors get stringified to '[np.float32(0.31...), ...]' and embedded again with sentence-transformers. No error, just a wrong projection.

A polars List or Array column, where non_null[0] comes back as a narwhals Series instead of a list. That one ends in a List to String cast error. test_vector_polars passes only because it sets modality="vector".

Fix

Check the column dtype first and return "vector" for nw.List/nw.Array with a numeric inner type, and accept np.number in the list check. Lists of strings still fall through to text. Added tests for both cases plus a polars list of strings.

Auto modality detection only accepted a Python list of int/float. Lists of numpy scalars (e.g. float32 embeddings turned into lists) and polars List/Array columns were treated as text, so the vectors were either stringified and embedded again or failed the text cast.
@donghaoren
donghaoren merged commit 56ca7d7 into apple:main Oct 1, 2026
8 checks passed
@donghaoren

Copy link
Copy Markdown
Collaborator

Thanks for fixing this!

@Yigtwxx
Yigtwxx deleted the fix/infer-vector-modality branch October 2, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants