polars-intervals
Fast interval algorithms for Polars, implemented in Rust. The first operation,
overlap_count, counts how many other intervals overlap each row without
building a table of overlapping pairs.
This is an early-stage v0.1 project. The API and supported Polars versions may
change; overlap_count is currently the only public Python operation.
Installation
To install a released version in a uv-managed project:
uv add polars-intervals
Or install with pip in your Python environment:
pip install polars-intervals
The distribution is named polars-intervals; the import is polars_intervals.
Supported Python and Polars versions are declared in
pyproject.toml.
Source and development installation
Building from source requires uv and
Rust installed through rustup, plus
your platform's native linker/build tools. Rustup selects the compiler from
rust-toolchain.toml.
git clone https://github.com/jplauri/polars-intervals.git
cd polars-intervals
uv sync --locked
uv run --locked python -c "import polars_intervals as pi; print(pi.overlap_count)"
This creates .venv and builds the Rust plugin through maturin. Run your scripts
with uv run --locked python your_script.py.
To use a local checkout from another uv-managed project, run this in that project:
uv add /path/to/polars-intervals
Quick start
import polars as pl
import polars_intervals as pi
df = pl.DataFrame({"start": [1, 3, 2, 2], "end": [3, 5, 4, 2]})
result = df.lazy().with_columns(pi.overlap_count("start", "end").alias("overlaps")).collect()
print(result["overlaps"].to_list())
# [1, 1, 2, 0]
pi.overlap_count(start, end) returns a Polars expression, with one non-null
UInt64 count per row in the original order. It works in select and
with_columns on eager or lazy frames. Use .alias(...) to name the output.
Either argument can also be a Polars expression, for example
pi.overlap_count(pl.col("start"), pl.col("end")).
Counts use the whole input collection. With
pi.overlap_count("start", "end").over("group"), comparisons stay within each
group.
Interval semantics
Intervals are half-open: [start, end). Two non-empty intervals overlap iff
a.start < b.end and b.start < a.end.
[1, 3)and[3, 5)touch but do not overlap.[1, 4)and[3, 5)overlap.[x, x)is valid and empty: it overlaps nothing and receives zero.- A row never counts itself. Identical non-empty intervals are separate rows and count each other.
Inputs and errors
| Input | Requirement |
|---|---|
start, end arguments |
Column names (str) or polars.Expr |
| Endpoint columns | Same dtype: Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, or UInt64 |
| Lengths | Equal; scalar expressions are not broadcast |
| Endpoint values | No nulls; start <= end in every row |
There is no automatic dtype conversion. Floats, strings, booleans, date/time types, and other dtypes are unsupported. Any null endpoint is rejected, including rows where both endpoints are null; null rows are not skipped or filled.
Invalid inputs raise a Polars error when the expression is evaluated (for a
lazy query, at collect()). A reversed interval (start > end) reports its
zero-based index in the input collection. Empty input with supported endpoint
dtypes returns an empty UInt64 result.
How it works
For n intervals, the Rust core sorts non-empty starts and ends independently
and uses binary searches to count overlaps in O(n log n) time and O(n)
additional space, preserving input order.
An inequality self-join followed by aggregation enumerates matching pairs.
Dense overlaps can create O(n²) pairs even though the final result has only n
counts. Avoiding that intermediate table can make overlap_count faster and use
less memory. Actual performance depends on the data, hardware, and query; see
the reproducible benchmark methodology
for the comparison and its limits.
Architecture
intervals-core: Rust interval algorithms with no production dependencies, generic over ordered endpoint types and independent of Polars and Python.- Polars plugin (
crates/polars-intervals): validates Polars inputs and adapts them to the core. Rust users can callpolars_intervals::overlap_count(&starts, &ends)with Polars Series. - Python API (
python/polars_intervals): a thin typed wrapper that registers the Rust function as a Polars expression.
Development and documentation
After uv sync --locked, run the Python checks:
uv run --locked ruff check .
uv run --locked ruff format --check .
uv run --locked pytest --doctest-modules python/polars_intervals tests
Run uv run --locked ruff format . to apply formatting.
Rust checks are cargo fmt --check, cargo test --workspace --locked, and
cargo clippy --workspace --all-targets --locked -- -D warnings.
Rust development and CI use the stable compiler pinned in
rust-toolchain.toml. Older compilers are untested; no separate minimum supported
Rust version (MSRV) is promised. Compiler updates should pass the Rust and compiled
Python plugin checks before merging.
Check the public Rust documentation with
cargo doc --workspace --no-deps --locked and RUSTDOCFLAGS="-D warnings" in the
environment. The generated Rust API reference is written to target/doc/.
The checkout is installed in editable mode, so Python edits are available
immediately. Run uv sync --locked after changing Rust code to rebuild the plugin.
Commit the lockfiles when updating dependencies.
The documentation includes this README and an API reference generated from the
overlap_count docstring. Edit the function's docstring to update its API
documentation. Preview or build locally with:
uv run --locked --isolated --only-group docs mkdocs serve
uv run --locked --isolated --only-group docs mkdocs build --strict
Building the docs does not require compiling the Rust plugin. The generated site
is written to target/docs/. Check the API examples against the installed plugin
with uv run --locked pytest --doctest-modules python/polars_intervals.
Maintainers can follow the release guide to prepare and publish a version.
Release files for polars-intervals 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| polars_intervals-0.1.0.tar.gz | 36.9 kB | Details |
Built distributions (wheels)
Total release size: 77.4 MB
Release files / polars_intervals-0.1.0.tar.gz
| Download URL | polars_intervals-0.1.0.tar.gz |
|---|---|
| Size | 36.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa1f57f5bfd269b3279adccd6c82b9141f473fabe5277fae58c3af0bf344de77
|
|
BLAKE2b-256 checksum How to use checksums |
fe942da7f40d1a659a54d89d2fc894645bcf7e4ca9daea5b17780bd321030334
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp314-cp314-win_amd64.whl
| Download URL | polars_intervals-0.1.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ffe3a62b56220dd553e9305088c6bed17436dbd701a1aeaf2f96bbc980a3a4ea
|
|
BLAKE2b-256 checksum How to use checksums |
fe3447918cf3234ee75c4dfc6704abf699ef09a0a6d756a34719a7fe122bd303
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | polars_intervals-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.6 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
9b4543fa7e1dd4b6a2bc2aae6eb99518d829882d02090b5380a37344fa657d91
|
|
BLAKE2b-256 checksum How to use checksums |
a389c632d76dfbf5158cf612e4fe01d04524a7bacb10a02abb5741ed51a20cc9
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp314-cp314-manylinux_2_28_aarch64.whl
| Download URL | polars_intervals-0.1.0-cp314-cp314-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
859f77b6da8b2ad748e2e5d1e3af7077636dfb2406889e8379b3373db4176dc5
|
|
BLAKE2b-256 checksum How to use checksums |
60c5b8e219aa3e5e962d41052888201dc4e5e3da1add7967c22c74a514e04d91
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | polars_intervals-0.1.0-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c836a5f969aff520e7c00a47042878b8332150d30d7db40e47a2b18344654479
|
|
BLAKE2b-256 checksum How to use checksums |
05163c961d29e402cb31f4d18c80d4cfa0eaad6f494c81fbffa2e4f29b57aee4
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl
| Download URL | polars_intervals-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.14 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
1c1f6522bc56e103a146eeca78af9d5cbadf5663ab3b5ab5ae63bca4ee6eaa39
|
|
BLAKE2b-256 checksum How to use checksums |
458548f14d1b1411bac1133dc71e5d551aadb47ce015060bff571726d50a203e
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp313-cp313-win_amd64.whl
| Download URL | polars_intervals-0.1.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7c139664bcbac775fb7f0532b9395f6c2c21931ce143321fb78d19345f559302
|
|
BLAKE2b-256 checksum How to use checksums |
8cdea91fc67d3491727b6bfa11ba3dcdd35931c8b9be4335506408d253144b38
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | polars_intervals-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.6 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
45454fc792c1b93e9fb03a36b547ef2033744da4632754d6fea7274221e1365d
|
|
BLAKE2b-256 checksum How to use checksums |
dfc884835f8946cbf64b74fd12324f40ab797daa876e7842d2e821aac51382a4
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp313-cp313-manylinux_2_28_aarch64.whl
| Download URL | polars_intervals-0.1.0-cp313-cp313-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
eafe90ec2665a2a0ed5152690402d9375788f08d79423c74b668695922829fd8
|
|
BLAKE2b-256 checksum How to use checksums |
33056a283869551c5913f213c1311e5d9938844dd32ab2cd69bcd9c809f4cbb5
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | polars_intervals-0.1.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f5dfbfe53e2f07fafb8d765beaa0c4bed8ce4c762a553c5094c528943502a031
|
|
BLAKE2b-256 checksum How to use checksums |
0e14b0742308dab8ddc24f6ce466127c924976b1885152d52c6294a7249ca313
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl
| Download URL | polars_intervals-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.13 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8f4d3b5ad1cc8796bbef26702b66fa4ab286e288412c63cb15eca6e1a4548adc
|
|
BLAKE2b-256 checksum How to use checksums |
3b29350343ac2b0f8887cd365fa4e6ef13b53bf55d927fe7ef1521c3fe051f41
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp312-cp312-win_amd64.whl
| Download URL | polars_intervals-0.1.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
90014be18bed4259e1ceaece7c077d4126f444b7d6a72e2d7605c08885e2b9e5
|
|
BLAKE2b-256 checksum How to use checksums |
9842941267e5b523b4ae1cff761f37fa170941c9e63e1e34694b03c845d375fb
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | polars_intervals-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.6 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e79fbccec9519215f225395ea60a0a07cade0e554fb9bc0db83156725a6b7eb2
|
|
BLAKE2b-256 checksum How to use checksums |
012da5f59a091ab7d37ee2b53ae8f037f97b23f3db285bd57860aafe206076ca
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl
| Download URL | polars_intervals-0.1.0-cp312-cp312-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
a50b7ca0d3345c084975ef5283a5d747f1232c53a6cd39297c037f69fa843f74
|
|
BLAKE2b-256 checksum How to use checksums |
0544769dc5717c527c06bdf3715873d15c499b8ed103125ab3a78aa4ba601053
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | polars_intervals-0.1.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fcf5443a3430626653e0620c53cb9bd7c19e709af1c4f7dbb4122e53070ef459
|
|
BLAKE2b-256 checksum How to use checksums |
d543428ca126a285a6ee65b2ce3aaf3bbd2cdb81bff572128788ee878254db7a
|
| 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 25, 2026.
Transparency logRelease files / polars_intervals-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl
| Download URL | polars_intervals-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.12 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
d871fdea08d226b8248741f9d1faea730eab72d571572bc688e951aa71495355
|
|
BLAKE2b-256 checksum How to use checksums |
30fbf2cb2238fbf40cbd6b8d1e76d67ae2033f3259e19669422c656398ae02c1
|
| 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 25, 2026.
Transparency log