Skip to main content

polars-list-math

polars-list-math is a Python/Rust package with list, JSON, and URL expression helpers for Polars.

Release notes and upgrade guidance are recorded in CHANGELOG.md.

Import the package once to register extra methods on Expr.list and Expr.str:

import polars as pl
import polars_list_math  # noqa: F401

For type-checked code, import the top-level expression helpers described below.

Install

pip install polars-list-math
# or
uv add polars-list-math

Requires Python 3.12+ and polars>=1.39.3.

Methods

Method Result Docs
Expr.list.zip(...) Zip lists into list[struct] List zip
Expr.list.combinations(...) Pair items in one list, optionally skipping self-pairs Combinations
Expr.list.combinations_to(...) Pair each item with each item from another list Combinations
Expr.list.similarity(...) Weighted similarity between two lists Similarity
Expr.list.mean_similarity(...) Mean similarity inside a nested-list row Similarity
Expr.list.mean_similarity_to(...) Mean similarity to reference nested lists Similarity
Expr.list.containment(...) Fraction of unique IDs found in another list Containment
Expr.list.mean_containment(...) Mean directed containment against peer lists Containment
Expr.list.mean_containment_to(...) Mean directed containment against reference lists Containment
Expr.str.json_object_items(...) Convert a JSON object to list[struct[key, value]] JSON object items
Expr.str.json_array_values(...) Convert a JSON array to list[str] JSON array values

Top-level expression helpers provide the statically typed API for Pyright, Pylance, and other type checkers:

Function Result Docs
list_zip(...) Zip lists into list[struct] List zip
list_combinations(...) Pair items in one list Combinations
list_combinations_to(...) Pair items from two lists Combinations
expected_value_of_game(...) Expected value of a sequential game Expected value of a game
list_similarity(...) Weighted similarity between two lists Similarity
list_mean_similarity(...) Mean similarity inside nested lists Similarity
list_mean_similarity_to(...) Mean similarity to reference nested lists Similarity
list_containment(...) Fraction of unique IDs found in another list Containment
list_mean_containment(...) Mean directed containment against peer lists Containment
list_mean_containment_to(...) Mean directed containment against reference lists Containment
json_object_items(expr, strict=False) Convert a JSON object to list[struct[key, value]] JSON object items
json_array_values(expr, strict=False) Convert a JSON array to list[str] JSON array values
url_query_encode(expr, doseq=False) Encode a Struct or key/value list as a URL query string URL query encoding
url_build(...) Assemble a URL from optional component expressions URL building
dfs_to_lazy_df(...) Expose DataFrame batches as a pushdown-aware LazyFrame source Examples

The Python helper py_list_similarity(...) computes weighted similarity for plain Python sequences. py_list_containment(...) computes directed set containment for Python sequences, ignoring ranks and duplicates.

The Expr.list and Expr.str methods are registered dynamically and remain available as convenient runtime syntax. Python type checkers cannot safely augment Polars' own namespace classes from another installed package, so use the equivalent top-level functions in code checked by Pylance or Pyright.

If a future Polars release ships native methods with the same names, this package leaves the native implementation untouched.

Quick Examples

from polars_list_math import (
    list_combinations,
    list_mean_similarity,
    list_similarity,
    list_zip,
)

df = pl.DataFrame(
    {
        "a": [[1, 2, 3]],
        "b": [[2, 1, 3]],
        "groups": [[[1, 2, 3], [1, 2, 3], [4, 5, 6]]],
    }
)

df.with_columns(
    list_similarity("a", "b").alias("similarity"),
    list_mean_similarity("groups").alias("mean_similarity"),
    list_combinations("a").alias("pairs"),
    list_zip("a", "b", fields=["a", "b"]).alias("zipped"),
)

Convert JSON strings to nested Polars values. String values stay strings, JSON null stays null, and other values become compact JSON strings. Invalid JSON returns null by default; pass strict=True to raise instead.

from polars_list_math import json_array_values, json_object_items

json_df = pl.DataFrame(
    {
        "object": ['{"name":"Ada","active":true,"note":null}'],
        "array": ['["python",42,true,null]'],
    }
)

json_df.select(
    json_object_items("object").alias("items"),
    json_array_values("array").alias("values"),
)

Encode query parameters and build URLs from expressions:

from polars_list_math import url_build, url_query_encode

pages = pl.DataFrame(
    {
        "host": ["example.com"],
        "path": ["/search"],
        "term": ["rust polars"],
        "page": [2],
    }
)

query = url_query_encode(pl.struct(q=pl.col("term"), page=pl.col("page")))

pages.select(
    url_build(
        scheme=pl.lit("https"),
        netloc="host",
        path="path",
        query=query,
    ).alias("url")
)

More complete, runnable examples are available in the examples directory.

Nested zip builder

ZipBuilder combines nested list columns with zip options and ordered eval/filter operations at each level. build() returns a normal Polars expression:

from polars_list_math import ZipBuilder

expr = (
    ZipBuilder("a", "b")
    .level(pad=True)
    .filter(pl.element().struct.field("a").is_not_null())
    .build("nested_zip")
)

The constructor configures the outer zip; each level() adds one inner zip. See the builder guide for transformations, broadcasting, and deeper nesting.

Performance experiments

Reproducible performance experiments live in the performance directory. Each experiment has its own README with the tested scenario, run instructions, environment, and recorded results.

The current dataframe_construction experiment compares construction of 30-column Polars DataFrames from a regular dataclass, a slotted dataclass, and a named tuple, including nested structs and lists.

uv run pytest performance/dataframe_construction -v -s

Development

make install
make develop
make test

Build and check the package locally:

make check-dist

Release steps are in docs/publishing.md.

Metadata

Release files for polars-list-math 0.6.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-list-math 0.6.0
File Size Uploaded Provenance
polars_list_math-0.6.0.tar.gz 47.8 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for polars-list-math 0.6.0
File
polars_list_math-0.6.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
polars_list_math-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
polars_list_math-0.6.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
polars_list_math-0.6.0-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details
polars_list_math-0.6.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
polars_list_math-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
polars_list_math-0.6.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
polars_list_math-0.6.0-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details

Total release size: 39.2 MB

Release files / polars_list_math-0.6.0.tar.gz

Download URL polars_list_math-0.6.0.tar.gz
Size 47.8 kB
Tags Source
SHA-256 checksum
How to use checksums
17fcc5d32c50cb734302409336036a58e5711dc96efe36b4005e1a2590e47863
BLAKE2b-256 checksum
How to use checksums
839d1d1428957505af04b1cc73927666371260f5f561e7ee639f9911db88a15c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / polars_list_math-0.6.0-cp313-cp313-win_amd64.whl

Download URL polars_list_math-0.6.0-cp313-cp313-win_amd64.whl
Size 4.9 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
1f053e2f75de966221cc41d997f8e38ad95e9a7c8cb8ef07c62a854942175b0b
BLAKE2b-256 checksum
How to use checksums
7158317471eb3b13d342c064863160b3a9ff46b413c1160d202da45ca6d129ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / polars_list_math-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_list_math-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 5.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0cdc1ce74c120c4a7a6bbb9495e27804b79b3d9b33dd7fa1ba70a46fc5953e07
BLAKE2b-256 checksum
How to use checksums
6daf3d7bd105afad0c3c0c779e292aed35d0aa183ee31fe97f92c2717dcd3817
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / polars_list_math-0.6.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL polars_list_math-0.6.0-cp313-cp313-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f93ff028d0e3c94964231dd30ffd84fd958094605e60fe4808fdcb6c3d567555
BLAKE2b-256 checksum
How to use checksums
4ad8684433ac0ff3a8c0eb32991698d7762cfdddf3398b855d61711c2320a348
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / polars_list_math-0.6.0-cp313-cp313-macosx_10_12_x86_64.whl

Download URL polars_list_math-0.6.0-cp313-cp313-macosx_10_12_x86_64.whl
Size 4.8 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
283afd86908e1881b9403c8e44e6b2a3f8cc11f83ea9932337ce213041f8ba22
BLAKE2b-256 checksum
How to use checksums
8ac317d3ac047c54bc386144c252a0d1e9c5ee9e4633b1bb68bea43977d85c6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / polars_list_math-0.6.0-cp312-cp312-win_amd64.whl

Download URL polars_list_math-0.6.0-cp312-cp312-win_amd64.whl
Size 4.9 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
2eb1ee4f02e210aae3b1cb238b85bc12054dd9689bcb59f58e1bc7d6d9c1ad21
BLAKE2b-256 checksum
How to use checksums
e7a01b00476be62f0ab3c1aa7545dfceabc1f7216b5853505bb6c3ec34eaa1cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / polars_list_math-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_list_math-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 5.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8daa0861a3893cab3f769cfa83cfb29591ae2a3ffb487418f8e1667e3bffea4e
BLAKE2b-256 checksum
How to use checksums
dfccdaa2e2b0c43a2b868cf051cd61a896b48ee48db2e3fb06280fbabbdd159f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / polars_list_math-0.6.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL polars_list_math-0.6.0-cp312-cp312-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e851b8f377454bfd7299e120f0213a8ec03a3759c88c9c87b51154a18cb62ba9
BLAKE2b-256 checksum
How to use checksums
733ce9cd2346b4a1957f068a3ed34fa381d475951fcb0512558afe559fa379b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / polars_list_math-0.6.0-cp312-cp312-macosx_10_12_x86_64.whl

Download URL polars_list_math-0.6.0-cp312-cp312-macosx_10_12_x86_64.whl
Size 4.8 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
31e786aa5dfc0eda8c30965bdf51e0b45b6b375825f3678396a0ced549b3d6fa
BLAKE2b-256 checksum
How to use checksums
c2944547a55c1c628557264bd13d99edeca6e3828e38564f74d3b09be3b5f75a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Security for polars-list-math 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for polars_list_math-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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