Skip to main content

An intervals library implemented in pure python, meant to be a drop-in replacment for the pyinterval library.

Project description

Extents - An Intervals Library in Pure Python

extents is an intervals library implemented in pure python. It draws its inspiration from the PyInterval library (github).

This library is capable of representing open, closed and semi-open/closed intervals. It also supports set operations on intervals (i.e., union, intersection and complement).

Examples:

Basic use cases:

Basic use of this library includes creating simple intervals, and manipulating them through set operations

from extents import interval        # the interval class represents a collection of intervals

ival1 = interval([0, 1])            # the singleton interval set containing the closed interval [0, 1]
print(ival1)                        # Interval([0, 1])
print(~ival1)                       # Interval((-inf, 0), (1, inf)) -- the interval set of (-inf, 0) and (1, inf) -- 
                                    # which compose the complement of [0, 1]

ival2 = interval((4, 5))            # the singleton interval set containing the open interval (4, 5)
print(ival2)                        # Interval((4, 5))
print(~ival2)                       # Interval((-inf, 4], [5, inf)) -- the interval set of (-inf, 4] and [5, inf) --
                                    # which are the complement of (4, 5)]

ival3 = interval([0, 1], [5, 6])    # the interval set [0, 1] and [5, 6]
ival4 = interval([0, 3], [4, 5.5])  # the interval set [0, 3] and [4, 5.5]
print(ival3 | ival4)                # the interval set [0, 3] and [4, 6], which is the union of ival3 and ival4
print(ival3 & ival4)                # the interval set [0, 1] and [5, 5.5], which is the intersection of ival3 and ival4

ival5 = interval([0, 1], [0.5, 3])  # intervals are automatically union-ed during construction.
print(ival5)                        # resulting in the interval [0, 3]

The output of the commands above would be:

Interval([0, 1])
Interval((-inf, 0), (1, inf))
Interval((4, 5))
Interval((-inf, 4], [5, inf))
Interval([0, 3], [4, 6])
Interval([0, 1], [5, 5.5])
Interval([0, 3])

Advanced use cases:

In order to construct a semi-open interval, you can import the Component and ComponentType, and construct the internal interval components.

For example,

from extents import interval, Component, ComponentType

ival = interval(Component(0, 1, ComponentType.HALF_CLOSED_LEFT),
                Component(5, 6, ComponentType.HALF_CLOSED_RIGHT)
                )
print(ival)  # construct the interval set: [0, 1), (5, 6]

Additional Examples:

See the tests/extents_test.py file.

Installation:

From github:

$ pip install git+https://github.com/swapp-ai/extents

From source:

$ git clone https://github.com/swapp-ai/extents
$ cd extents
$ pip install .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

extents-0.2.2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

extents-0.2.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file extents-0.2.2.tar.gz.

File metadata

  • Download URL: extents-0.2.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for extents-0.2.2.tar.gz
Algorithm Hash digest
SHA256 34f494fe8815bda4a017b880998f08600366ad47c9406d46269c195c15f6441b
MD5 5f1011234a104e8891f7e6ad91feed0e
BLAKE2b-256 c02cc86c7a2c407e19100aa7a9bf714a567476f17158ba5955306c23aaa1beb0

See more details on using hashes here.

File details

Details for the file extents-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: extents-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for extents-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 acd987b1d8a49dcc43b34d420055ace9d46fc7f1c6786dda58d183e724d8bf8c
MD5 921de66c74d78d3d181b97af6f235b81
BLAKE2b-256 8fdbfcdc64c988b86e6c25b3d6e94455f7a5e00c113692ae3233f382017e11a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page