Skip to main content

PolarsGrouper

PolarsGrouper is a Rust-based extension for Polars that provides efficient graph analysis capabilities, with a focus on component grouping and network analysis.

Core Features

Component Grouping

  • super_merger: Easy-to-use wrapper for grouping connected components
  • super_merger_weighted: Component grouping with weight thresholds
  • Efficient implementation using Rust and Polars
  • Works with both eager and lazy Polars DataFrames

Additional Graph Analytics

  • Shortest Path Analysis: Find shortest paths between nodes
  • PageRank: Calculate node importance scores
  • Betweenness Centrality: Identify key bridge nodes
  • Association Rules: Discover item relationships and patterns

Installation

pip install polars-grouper

# For development:
python -m venv .venv
source .venv/bin/activate
maturin develop

Usage Examples

Basic Component Grouping

The core functionality uses super_merger to identify connected components:

import polars as pl
from polars_grouper import super_merger

df = pl.DataFrame({
    "from": ["A", "B", "C", "D", "E", "F"],
    "to": ["B", "C", "A", "E", "F", "D"],
    "value": [1, 2, 3, 4, 5, 6]
})

result = super_merger(df, "from", "to")
print(result)

Weighted Component Grouping

For cases where edge weights matter:

from polars_grouper import super_merger_weighted

df = pl.DataFrame({
    "from": ["A", "B", "C", "D", "E"],
    "to": ["B", "C", "D", "E", "A"],
    "weight": [0.9, 0.2, 0.05, 0.8, 0.3]
})

result = super_merger_weighted(
    df, 
    "from", 
    "to", 
    "weight",
    weight_threshold=0.3
)
print(result)

Additional Graph Analytics

Shortest Path Analysis

Find shortest paths between nodes:

from polars_grouper import calculate_shortest_path

df = pl.DataFrame({
    "from": ["A", "A", "B", "C"],
    "to": ["B", "C", "C", "D"],
    "weight": [1.0, 2.0, 1.0, 1.5]
})

paths = df.select(
    calculate_shortest_path(
        pl.col("from"),
        pl.col("to"),
        pl.col("weight"),
        directed=False
    ).alias("paths")
).unnest("paths")

PageRank Calculation

Calculate node importance:

from polars_grouper import page_rank

df = pl.DataFrame({
    "from": ["A", "A", "B", "C", "D"],
    "to": ["B", "C", "C", "A", "B"]
})

rankings = df.select(
    page_rank(
        pl.col("from"),
        pl.col("to"),
        damping_factor=0.85
    ).alias("pagerank")
).unnest("pagerank")

Association Rule Mining

Discover item relationships:

from polars_grouper import graph_association_rules

transactions = pl.DataFrame({
    "transaction_id": [1, 1, 1, 2, 2, 3],
    "item_id": ["A", "B", "C", "B", "D", "A"],
    "frequency": [1, 2, 1, 1, 1, 1]
})

rules = transactions.select(
    graph_association_rules(
        pl.col("transaction_id"),
        pl.col("item_id"),
        pl.col("frequency"),
        min_support=0.1
    ).alias("rules")
).unnest("rules")

Betweenness Centrality

Identify bridge nodes:

from polars_grouper import betweenness_centrality

df = pl.DataFrame({
    "from": ["A", "A", "B", "C", "D", "E"],
    "to": ["B", "C", "C", "D", "E", "A"]
})

centrality = df.select(
    betweenness_centrality(
        pl.col("from"),
        pl.col("to"),
        normalized=True
    ).alias("centrality")
).unnest("centrality")

Performance

The library is implemented in Rust for high performance:

  • Efficient memory usage
  • Fast computation for large graphs
  • Seamless integration with Polars' lazy evaluation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for 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_grouper-0.5.0.tar.gz (35.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

polars_grouper-0.5.0-cp310-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

polars_grouper-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.2 MB view details)

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

polars_grouper-0.5.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (5.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

polars_grouper-0.5.0-cp310-abi3-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

polars_grouper-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file polars_grouper-0.5.0.tar.gz.

File metadata

  • Download URL: polars_grouper-0.5.0.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for polars_grouper-0.5.0.tar.gz
Algorithm Hash digest
SHA256 eea40a1a2b7668b54a1f0584cd9322fb8dc412cc484bd8d3dd705c4701628bab
MD5 01c2493d7c1ac087f55c2e4a03eb6de3
BLAKE2b-256 706375a0d162bbe7d43abb2d8ac4f3300599c9a98e0e5ef27dbd289dc70c16cc

See more details on using hashes here.

File details

Details for the file polars_grouper-0.5.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_grouper-0.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 27f9f1fc13844a26f82643c97239bf4b7e65aecb65373e31455f51de04096862
MD5 6b7c64bb53012829c03b82a988ea726e
BLAKE2b-256 6bd02a2774f6aacf521cfb9749d6785cbbb8f579de677b0d97411cf88c796524

See more details on using hashes here.

File details

Details for the file polars_grouper-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_grouper-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c2a29339d3be4bdecc9cbb8ca817896e137766f95c58ea46d74c0c6d27f7b8f4
MD5 34e095dac36650178fff3d5a91993fb2
BLAKE2b-256 461629bb7e00ec76213318d7ff8866745d190650f2fde37011a5f2621e74f771

See more details on using hashes here.

File details

Details for the file polars_grouper-0.5.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for polars_grouper-0.5.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 53b7802ffe423403618a1d59def3d45292a94457e19db64dd812c5cd0d22e5f1
MD5 7626a035c4d4a48e2f6de832c9cce5c9
BLAKE2b-256 96c91227881c740b066838b51fb84e84d13532ef06e0b65a8b1508a31c6a49d5

See more details on using hashes here.

File details

Details for the file polars_grouper-0.5.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_grouper-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f0b801020ef7ab07c40e575f5caaac10bbad0593ed154798a4b74e56ce56a83
MD5 321e22e5e56f6f36b854fb8ee21627bf
BLAKE2b-256 9e99c513b20d28d96621eddff322acd00c686191367aaa3a8930735fed906457

See more details on using hashes here.

File details

Details for the file polars_grouper-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_grouper-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dbc53f8d0bb65949238d5fdfb7a9724c6bd1d3bc6067eca1edbbaac31ebcb26a
MD5 5594ae7ff7394260589212b3446c199e
BLAKE2b-256 78a495d10e2963393974c0651cfb23d03c2627e14e8b0aa5474d6f92374292bb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

6 files

0.4.0

8 files

0.3.0

6 files

0.2.0

6 files

0.1.0

6 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