Skip to main content

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

  1. Marco Gorelli's Tutorial on writing Polars Plugin. See here.
  2. The Helix Editor team for the Nucleo fuzzy matching library.

Project details


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_match-0.1.3.tar.gz (18.7 kB view details)

Uploaded Source

Built Distributions

polars_fuzzy_match-0.1.3-cp38-abi3-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.8+ Windows x86-64

polars_fuzzy_match-0.1.3-cp38-abi3-win32.whl (2.4 MB view details)

Uploaded CPython 3.8+ Windows x86

polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (3.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ i686

polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (4.2 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARMv7l

polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.whl (4.5 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.12+ i686

polars_fuzzy_match-0.1.3-cp38-abi3-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

polars_fuzzy_match-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

Details for the file polars_fuzzy_match-0.1.3.tar.gz.

File metadata

  • Download URL: polars_fuzzy_match-0.1.3.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.5.0

File hashes

Hashes for polars_fuzzy_match-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e7833d01e21c71410dd8e4d7f90fe71a090c2e9c29b2bc352cb6553629dbeef9
MD5 bdf4d3b2cc318caf3d19da479b6c9629
BLAKE2b-256 64a74a469bf20767dcef723a73f20990d151496a10c5fcd80ea299540261d6c7

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7a796162b07f25adf416817b762c31f5519909c6d8c1aa52558f38938d82a8b9
MD5 2744c20808b54125efdefba260825381
BLAKE2b-256 fd85950ee35b550a6ecb1e0bb7f5ecbf62c65bf1e68eb526223e27fdea3e7a06

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-win32.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 0b84a0b04f37be7ba60b151ab74d3c6ee1953e3b90f7f89524b2d6d486ea20cf
MD5 b8a3715f90ad6dbe3aa7d52bc493a7cc
BLAKE2b-256 fd67dc73cb075031d2e2ec96da6c7e487b18ff2c85c4b6149f50c5c6e483e8af

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0c11831ba69160c30147312fbf02f55d8228b2936325f00b6b88784dceae35a4
MD5 5619ef6682aaa29b60c74d7691c2fa44
BLAKE2b-256 fcb9e9edcd11b301f2f8245e0fb7c05bbe8da0c3449331dc36b406163b70f24a

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b391030d0577e44f21174651f10e92555d55520d836336a566ffa7c303752f54
MD5 69c3525300330c7c652b574b56d110d7
BLAKE2b-256 6d6c9b93e2cde32d31bf9e72e51ee1bc7ae70bbaa315b5516597f0c5c749dfe0

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 3d9f64662696e36985c36cd24cf806095afee38efe688cc5df11cd2d622aa2dd
MD5 9233db61e2d4ddb8a5d5ebb4229e1ae5
BLAKE2b-256 84971d204d808e7fa81fe9aed56b42b82e3d5b9aec398dcaa63c39418dec910b

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c8634c6708088a17c25437ccfa0611fbf5c484da29ed906c789ca6d427f43b78
MD5 2c330f5dd0672d560466029590a6c07f
BLAKE2b-256 f1f83542fb3aefd4cfd8bacee24711c8d052e3f49d3a3b229584383d3603197d

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 0170616d965d8b1f7ff35777f86b1f5fcbcd4c566ad7790f96ceb39f95bc01d4
MD5 b736ed55131732187c5667e15f74a700
BLAKE2b-256 2880d97d6102a6c6a66177c3b0a6d87a88c6baee8edfb969bbfe42ed3118d616

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bdf9af7aab9a5846250134b4893e3504ead74cdd3f93cff900745e9e977f6870
MD5 82b6511e903e6ba79002021afc2311d2
BLAKE2b-256 ebd4967f1bbc2b00e75f633b8dd90d443a2e0837a57b6912ad393a2460f8f688

See more details on using hashes here.

File details

Details for the file polars_fuzzy_match-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_fuzzy_match-0.1.3-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3b3991d6adaeb3a95646df5e43fea97d3528319156ac7667e72e13d5bff8e30e
MD5 fd11aa5b33dc1abe532015cc04f268dc
BLAKE2b-256 ae811d8d2152aa5328d46196309f5cfba1d522d07d6fd1b761827e097c29e39b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page