polars-distance
raw JSON → 0.5.3 verified Mon Apr 27 auth: no python
Polars plugin for pairwise distance functions. Version 0.5.3 supports f32 and uint64 types. Release cadence is irregular, with minor/patch releases every few months.
pip install polars-distance Common errors
error AttributeError: module 'polars_distance' has no attribute 'pairwise_euclidean' ↓
cause Attempting to call the distance function as a top-level module attribute instead of using the expression API.
fix
Use
pld.col('a').pairwise_euclidean(pld.col('b')) inside df.with_columns() or similar. error polars.exceptions.ComputeError: ... dtype is not supported ↓
cause Passing a column with an unsupported dtype (e.g., categorical) to a distance function.
fix
Cast the column to a supported dtype:
df.with_columns(pl.col('col').cast(pl.Utf8)). Warnings
breaking Version 0.3.2 removed categorical dtype support. If you rely on categorical columns in list/set distances, upgrade with caution. ↓
fix Convert categorical columns to string or numeric types before applying distance functions.
deprecated The package previously allowed direct import of distance functions from polars_distance.polars. As of 0.5.0, the recommended import is the root module. ↓
fix Change imports to `import polars_distance as pld` and use `pld.col(...).pairwise_*`.
gotcha polars-distance requires Polars >= 0.20.0 and uses Polars plugins API. Incompatible with older Polars versions. ↓
fix Ensure Polars is updated: `pip install polars>=0.20.0`.
Imports
- col wrong
import polars_distance.polars as pldcorrectimport polars_distance as pld
Quickstart
import polars as pl
import polars_distance as pld
df = pl.DataFrame({
"a": [[1.0, 2.0], [3.0, 4.0]],
"b": [[1.5, 2.5], [3.5, 4.5]]
})
df.with_columns(
dist=pld.col("a").pairwise_euclidean(pld.col("b"))
)