Skip to main content

polars_simed

Description

Implements an approximate join of two polars dataframes based on string columns.

Right now, we use a fixed vectorization, which is applied on the fly and eventually used in a sparse matrix multiplication combined with a top-n selection. This produces the cosine similarities of the individual string pairs.

The join_sim function is similar to a left join or join_asof but for strings instead of timestamps.

Installation

pip install polars_simed

Development

We use uv for python package management. Furthermore, you need rust to be installed, see install rust. You won't need to activate an enviroment by yourself at any point. This is handled by uv. To get started, run

# install python dependencies and compile the rust code
make install 
# run tests
make test

Usage

import polars as pl
import polars_simed as ps

df_left = pl.DataFrame(
    {
        "name": ["alice", "bob", "charlie", "david"],
    }
)

df_right = pl.DataFrame(
    {
        "name": ["ali", "alice in wonderland", "bobby", "tom"],
    }
)

df = ps.join_sim(
    df_left,
    df_right,
    on="name",
    top_n=4,
)

shape: (3, 3)
┌───────┬──────────┬─────────────────────┐
│ name  ┆ sim      ┆ name_right          │
│ ---   ┆ ---      ┆ ---                 │
│ str   ┆ f32      ┆ str                 │
╞═══════╪══════════╪═════════════════════╡
│ alice ┆ 0.57735  ┆ ali                 │
│ alice ┆ 0.522233 ┆ alice in wonderland │
│ bob   ┆ 0.57735  ┆ bobby               │
└───────┴──────────┴─────────────────────┘

Performance

A benchmark can be executed with make run-bench. In general, the performance heavily depends on the length of the dataframes. By default, the computation is parallelized over the left dataframe. However, serveral benchmarks showed that if the right dataframe is much bigger than the left dataframe and no normalization is applied, it is faster to parallelize over the right dataframe.

If no normalization is applied, the performance is usually better since the a small uint type will be used for the sparse matrix multiplication, e.g. u16. Otherwise, all types will be of 32 bit size.

References

The implementation is based on an algorithm used in sparse_dot_topn, which itself is an improvement of the scipy sparse matrix multiplication.

Metadata

Release files for polars-simed 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars-simed 0.4.0
File Size Uploaded
polars_simed-0.4.0.tar.gz 54.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for polars-simed 0.4.0
File
polars_simed-0.4.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl PyPy 3.11 PyPy 3.11 7.3 Linux glibc 2.17+ x86-64 Details
polars_simed-0.4.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
polars_simed-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
polars_simed-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
polars_simed-0.4.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
polars_simed-0.4.0-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 31.0 MB

Release files / polars_simed-0.4.0.tar.gz

Download URL polars_simed-0.4.0.tar.gz
Size 54.5 kB
Tags Source
SHA-256 checksum
How to use checksums
53f3252d791e6ac238bf8cb239f1e8aa5d189b98c704e31d20f60be7c727e899
BLAKE2b-256 checksum
How to use checksums
460726ea6f524864a8f82d7f56504f3162cc5535861a50ce383f09f20ea9a5b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.12.6

Release files / polars_simed-0.4.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_simed-0.4.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 5.7 MB
Tags Linux glibc 2.17+ x86-64 PyPy 3.11 PyPy 3.11 7.3
SHA-256 checksum
How to use checksums
16c4738eb031b51212b898d5e8ecad2ff492d853367c28e505431e5cee6347b6
BLAKE2b-256 checksum
How to use checksums
268969ea1c2adc91d98955f426a21a882037b91db1905586a1f591e74154170b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.12.6

Release files / polars_simed-0.4.0-cp38-abi3-win_amd64.whl

Download URL polars_simed-0.4.0-cp38-abi3-win_amd64.whl
Size 5.6 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
3384e5ff109c8c4e7fb42bd5562f57d8b7622e769c089fe645aa869546116568
BLAKE2b-256 checksum
How to use checksums
2af76e9651cbed700b583f17cbfe52c4bc1cdadf80e0435692ed6a0a937098f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.12.6

Release files / polars_simed-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_simed-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 5.7 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
4229917cc08fa021eaccc10322b6bf570f30977e1a5dafa00929e3fe7dc4f376
BLAKE2b-256 checksum
How to use checksums
cbe51b2efd88b1bdffa8c1b7abc7b47b1ff5048d6983caf03636397cfcb233a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.12.6

Release files / polars_simed-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL polars_simed-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 5.2 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
bc221942ad649ea02b66b389f7993f95bb5a2adc4e99aece539947ea60131ec6
BLAKE2b-256 checksum
How to use checksums
c0757a409dd47037333ca068f939f3d479809fe23e02d57f59c52fe0ba5fb2ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.12.6

Release files / polars_simed-0.4.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL polars_simed-0.4.0-cp38-abi3-macosx_11_0_arm64.whl
Size 4.2 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6786325fe6ec4dd09be1fa2fee47bc0895dc4722ad09c1a64787e14d181442ed
BLAKE2b-256 checksum
How to use checksums
dfdbc9c66710da8eab51d0baea0c8395977972c1e3424f8abacd98fff735732d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.12.6

Release files / polars_simed-0.4.0-cp38-abi3-macosx_10_12_x86_64.whl

Download URL polars_simed-0.4.0-cp38-abi3-macosx_10_12_x86_64.whl
Size 4.6 MB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
46853d87af5c769276297db797fac1b849fab80acf1c71cffa0f440c7d5b8f2b
BLAKE2b-256 checksum
How to use checksums
fd0a0f0d95d19fa2ebc8f31e16096654ec340b52aff37b4a3a9288162d27813c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.12.6

Release history Release notifications | RSS feed

This release

0.4.0 This release

7 release files

0.3.4

6 release files

0.3.3

5 release files

0.3.2

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page