Skip to content

polars-intervals

Use polars-intervals to count overlaps and containment, measure nesting, assign lanes, and select intervals for scheduling or covering. It supports eager and lazy Polars queries.

Use interval geometry to merge covered ranges, subtract exclusions, or intersect two collections. Use per-query coverage statistics to measure coverage inside each reporting window while keeping its original columns and row order.

Install

Requires Python 3.12+.

pip install polars-intervals

Or with uv: uv add polars-intervals.

Your first query

Count how many other intervals overlap each row:

import polars as pl
import polars_intervals as pi

df = pl.DataFrame(
    {
        "start": [0, 1, 2],
        "end": [2, 3, 4],
    }
)
result = (
    df.lazy()
    .with_columns(
        pi.overlap_count("start", "end").alias("overlaps"),
    )
    .collect()
)

print(result["overlaps"].to_list())  # [1, 2, 1]

Intervals include their start and exclude their end, so touching intervals do not overlap.

Next steps

  • Usage: input rules and examples for each operation.
  • API reference: parameters, return types, and input requirements.
  • Benchmarks: runtimes and native Polars comparisons.
  • Contributing: source builds and development.