Fast fuzzy string matching for Polars DataFrames, powered by Rust
Project description
Polars Fuzzy
Fast fuzzy string matching for Polars DataFrames, powered by Rust.
Installation
pip install polars-fuzzy
Quick Start
import polars as pl
import polars_fuzzy as pf
df = pl.DataFrame({"name": ["John Smith", "Jane Doe", "Benjamin", "Johnny", None]})
# Raw fuzzy score - higher is better, null means no match
print(df.with_columns(pf.fuzzy_score("name", "john").alias("score")))
# ┌────────────┬───────┐
# │ name ┆ score │
# │ --- ┆ --- │
# │ str ┆ u32 │
# ╞════════════╪═══════╡
# │ John Smith ┆ 114 │
# │ Jane Doe ┆ null │
# │ Benjamin ┆ null │
# │ Johnny ┆ 114 │
# │ null ┆ null │
# └────────────┴───────┘
# Normalized score - 0.0 to 1.0, easier to threshold
print(df.with_columns(pf.fuzzy_score_normalized("name", "john").alias("score")))
# Filter - only rows that match
print(df.filter(pf.fuzzy_score("name", "john").is_not_null()))
# Sort by best match
print(
df.with_columns(pf.fuzzy_score("name", "john").alias("score")).sort(
"score", descending=True, nulls_last=True
)
)
Column vs Column
Useful for record linkage - matching names across two datasets.
customers = pl.DataFrame({"name": ["John Smith", "Jane Doe"]})
invoices = pl.DataFrame({"client": ["Jon Smith", "J. Doe"]})
customers.join(invoices, how="cross").with_columns(
pf.fuzzy_score_normalized("name", "client").alias("score")
).filter(pl.col("score").is_not_null()).sort("score", descending=True)
Fuzzy JOIN
result = pf.fuzzy_join(
customers, invoices,
left_on="name",
right_on="client",
threshold=0.8,
)
Options
pf.fuzzy_score(
"name", # haystack - column name or pl.Expr
"john", # query - string literal, column name, or pl.Expr
case_sensitive=False, # default: False
normalize=True, # accent folding: "café" matches "cafe"
)
Performance
- Zero heap allocations in the per-row hot loop
- Literal patterns compiled once per column, not per row
- Nulls propagated without entering the matcher
- Backed by Nucleo - the fuzzy engine powering the Helix editor
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
polars_fuzzy-0.1.1.tar.gz
(28.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_fuzzy-0.1.1.tar.gz.
File metadata
- Download URL: polars_fuzzy-0.1.1.tar.gz
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67c405891455790d55fc7859caf51db729a6bf65d4920df366081c01ee2464ff
|
|
| MD5 |
ad25a2c75b0b1d6a6c68d4158ecee7c5
|
|
| BLAKE2b-256 |
0f0a4b7190beab8d55a913fc2b1599d457119ccc59e5c78e1d98e2a82cc7716c
|
File details
Details for the file polars_fuzzy-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polars_fuzzy-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab536f40f809b34cc7b83ff5c07eea5a1b67bbfeaf1c002d9cc124b032703bb8
|
|
| MD5 |
29408d1a5a7a7c25784aa308afafb91c
|
|
| BLAKE2b-256 |
1f7b61c62b67c7d7d67367f1bce6456e2c0737650127bea2668b76e870529d86
|