Skip to main content

polars_sim

Polars >= 1 Compatibility Test

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_sim

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_sim 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-sim 0.4.1

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-sim 0.4.1
File Size Uploaded
polars_sim-0.4.1.tar.gz 59.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for polars-sim 0.4.1
File
polars_sim-0.4.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl PyPy 3.10 PyPy 3.10 7.3 Linux glibc 2.17+ ARM64 Details
polars_sim-0.4.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl PyPy 3.9 PyPy 3.9 7.3 Linux glibc 2.17+ ARM64 Details
polars_sim-0.4.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
polars_sim-0.4.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
polars_sim-0.4.1-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
polars_sim-0.4.1-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 30.9 MB

Release files / polars_sim-0.4.1.tar.gz

Download URL polars_sim-0.4.1.tar.gz
Size 59.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4cfdfa4a748a127937932371d0fb2c2c252b4dd309911c75a9168300acb88a1e
BLAKE2b-256 checksum
How to use checksums
442ff44631cae4d760ea136a954c8094f4d5c610050a4bdc76e33ff63bba39f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.10.2

Release files / polars_sim-0.4.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL polars_sim-0.4.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 4.9 MB
Tags Linux glibc 2.17+ ARM64 PyPy 3.10 PyPy 3.10 7.3
SHA-256 checksum
How to use checksums
f5abacc309cf7416887dc3e59fc9a477e352f565538e69e3a10ff3f2e115e340
BLAKE2b-256 checksum
How to use checksums
6462f5317afa5075e2f73c42709023b123e19901e1352fdf10f330328eed460a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.10.2

Release files / polars_sim-0.4.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL polars_sim-0.4.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 4.9 MB
Tags Linux glibc 2.17+ ARM64 PyPy 3.9 PyPy 3.9 7.3
SHA-256 checksum
How to use checksums
5f5eb5188655b99380a2a1c0ce3b997707cdcfb9c87fb08f256b464dd5641cac
BLAKE2b-256 checksum
How to use checksums
7b5c1bb44e2307ec7918b9f6c7a8018d413c6da7c55368c18c1cdbdd303fc954
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.10.2

Release files / polars_sim-0.4.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_sim-0.4.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 6.3 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
12094a747e9bd904dcb7be1a09b1f3270ae6ef66a48500fd5306ffa9b734110a
BLAKE2b-256 checksum
How to use checksums
f55a15c6cdf374f3a889a3edbf251f1e3d734ba31e36e6ee4abcabeb578f0656
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.10.2

Release files / polars_sim-0.4.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL polars_sim-0.4.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 4.9 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
58bb41b3345642d3a8154fd34f63b172baf45f9da78b13babd19651a736d6ecf
BLAKE2b-256 checksum
How to use checksums
bda4159714a496a095bb9bc8cb0cfbdb6a1808f037f97615b01816dac759d3f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.10.2

Release files / polars_sim-0.4.1-cp38-abi3-macosx_11_0_arm64.whl

Download URL polars_sim-0.4.1-cp38-abi3-macosx_11_0_arm64.whl
Size 4.7 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c246ec25f4d351483b73330ecee317b4c11d12e8e008d504d836e27bf36cace0
BLAKE2b-256 checksum
How to use checksums
f7a38e91a66576347fbfd52a07d3164b687923cb700074abde0c54803b75bafa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.10.2

Release files / polars_sim-0.4.1-cp38-abi3-macosx_10_12_x86_64.whl

Download URL polars_sim-0.4.1-cp38-abi3-macosx_10_12_x86_64.whl
Size 5.1 MB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
dcaec104ca73b393b1e0ad2fbfc7df9b5056500d50e0c689cc29fec5c7256670
BLAKE2b-256 checksum
How to use checksums
8ff450f28f7cfe27abcf8b066aa90d401d44b61657320d0094442851d7605a0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.10.2

Release history Release notifications | RSS feed

This release

0.4.1 This release

7 release files

0.3.6

9 release files

0.3.2

9 release files

0.3.1

9 release files

0.3.0

5 release files

0.2.3

5 release files

0.1.3

5 release files

0.1.2

5 release files

0.1.1

5 release files

0.1.0

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