Polars extension for fzf-style fuzzy matching
Project description
Polars Fuzzy Matching
Installation
pip install polars
pip install polars-fuzzy-match
Usage
With both the plugin and polars installed, usage is as follows:
import polars as pl
from polars_fuzzy_match import fuzzy_match_score
df = pl.DataFrame(
{
'strs': ['foo', 'foo quz BAR', 'baaarfoo', 'quz'],
}
)
pattern = 'bar'
out = df.with_columns(
score=fuzzy_match_score(
pl.col('strs'),
pattern,
)
)
print(out)
This outputs:
shape: (4, 2)
┌─────────────┬───────┐
│ strs ┆ score │
│ --- ┆ --- │
│ str ┆ u32 │
╞═════════════╪═══════╡
│ foo ┆ null │
│ foo quz BAR ┆ 88 │
│ baaarfoo ┆ 74 │
│ quz ┆ null │
└─────────────┴───────┘
When there is no match, score is null
. When the pattern matches the value in
the given column, score is non-null. The higher the score, the closer the value
is to the pattern. Therefore, we can filter out values that do not match and
order by score:
pattern = 'bar'
out = (
df.with_columns(
score=fuzzy_match_score(
pl.col('strs'),
pattern,
)
)
.filter(pl.col('score').is_not_null())
.sort(by='score', descending=True)
)
print(out)
This outputs:
shape: (2, 2)
┌─────────────┬───────┐
│ strs ┆ score │
│ --- ┆ --- │
│ str ┆ u32 │
╞═════════════╪═══════╡
│ foo quz BAR ┆ 88 │
│ baaarfoo ┆ 74 │
└─────────────┴───────┘
Fzf-style search syntax
This plugin supports Fzf-style search syntax for the pattern. It's worth noting that this section is taken almost verbatim from the Fzf README:
Pattern | Match type | Description |
---|---|---|
bar |
fuzzy | items that fuzzy match bar e.g. 'bXXaXXr' |
'foo |
substring exact match | items that include foo e.g. 'is foo ok' |
^music |
prefix exact match | items that start with music |
.mp3$ |
suffix exact match | items that end with .mp3 |
!fire |
inverse exact match | items that do not include fire |
!^music |
inverse prefix exact match | items that do not start with music |
!.mp3$ |
inverse suffix exact match | items that do not end with .mp3 |
Credits
- Marco Gorelli's Tutorial on writing Polars Plugin. See here.
- The Helix Editor team for the Nucleo fuzzy matching library.
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
Built Distributions
File details
Details for the file polars_fuzzy_match-0.1.5.tar.gz
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0826613117e424a44eff7ce74b02655b570704fbbe4cb796fe93b9f45353a89d |
|
MD5 | 9cc5d020cd7bbf38be80bf400e58cb19 |
|
BLAKE2b-256 | ea29d1526913208ba7d6ed295271ac4a226ab72770ba4ad96a066949eb24510a |
File details
Details for the file polars_fuzzy_match-0.1.5-cp38-abi3-win_amd64.whl
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66aba4f763ee1ce2fefe42d995b6dad9b77de1e7407319edcb3a787fdc32e0f1 |
|
MD5 | c815de6b5da38dc2e10272e4e3020101 |
|
BLAKE2b-256 | 838962716219ff87b6e9431b4d85479a9190b82db27e9f284ca304e1016a0d1f |
File details
Details for the file polars_fuzzy_match-0.1.5-cp38-abi3-win32.whl
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5-cp38-abi3-win32.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a824a07d13458508b39388ae4f69377f6d2113f4ecf0062bf799d07ca242d66b |
|
MD5 | 8a717738b1f84c2ae361dc301633c111 |
|
BLAKE2b-256 | 66482a602b4be4eb860fd275ec918af26cb08fdfdb145a15cba32bef8d45764b |
File details
Details for the file polars_fuzzy_match-0.1.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 586f58cef000a53e1e74d8483156c145496aab67605f68f9f44a3f9b5a68413c |
|
MD5 | a9cb8e858701189871bb44024871c05e |
|
BLAKE2b-256 | c243816669882f93959cad67bf855bdde993935b68fbfe8d2c2790f3569b596b |
File details
Details for the file polars_fuzzy_match-0.1.5-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f3d4b79885e09f62e0260a04fc87addf957cb4ec6a8b31c5fc48b20887dc5a5 |
|
MD5 | 0e73ec36b564911c308face43958b3eb |
|
BLAKE2b-256 | 68ca8e741ccbbbc4644db5304bd59f1d6718ace3b208d0edd5c19b6a2c601ff4 |
File details
Details for the file polars_fuzzy_match-0.1.5-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f07cc4b62c4030861209f759336426e36a5ffc19df3e98ca9aa10ceeac55393 |
|
MD5 | 28fafccded8d82f4f404ac3a51013763 |
|
BLAKE2b-256 | e1fec31cde16311072d7a23bc0751416fb56865f5885f9ae9780656fb8b09bd8 |
File details
Details for the file polars_fuzzy_match-0.1.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7abc7774d5baa67d9bf829063a09d26f0c45bd2e859def7d9035e2ab67aca8d |
|
MD5 | 2731cadb6330d2134c7b55bbee799d8c |
|
BLAKE2b-256 | c59a9fa1847fbe0ebddccb20e4758ec21a68cd6b98686f0969dfdb493345509f |
File details
Details for the file polars_fuzzy_match-0.1.5-cp38-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0052f3c10137b8610fec52edeca2edd4aa76654150cab589f31aec6ca6d3b22 |
|
MD5 | 65ddf5fcfd08e439a9ec1dd286a028e9 |
|
BLAKE2b-256 | 173718de858e81a34df13395dd038f2b03f48804966022689124fcaeafb6b8d3 |
File details
Details for the file polars_fuzzy_match-0.1.5-cp38-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: polars_fuzzy_match-0.1.5-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35666f26403341149da8f8804cd0af8cbb7202ec809c2af49fa09d922eba7281 |
|
MD5 | 75f2bafb84783a110bee96a466aef920 |
|
BLAKE2b-256 | 49774b63bd50bf2a15123d2cf2524be6d88ff3686456d207d540b6f264b8598d |