Registry / data / intervals

intervals

JSON →
library0.9.2pypypi✓ verified 85d ago

The `intervals` library (version 0.9.2) provides basic tools for handling intervals or ranges of comparable objects in Python. It supports defining closed, open, or half-open intervals and performing operations such as checking for containment. This specific package, maintained by kvesteri, appears to be abandoned, with no updates since 2016, and its functionality has largely been superseded by other, more actively maintained interval libraries like `portion` (which itself evolved from a library called `python-intervals`).

pip install intervals
INSTALL
IMPORT
SIG · INTERVALS
I
intervals
datapythonv0.9.2
Install
2.6s avg
Import
10ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.010s · 19.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.6s · import 0.010s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Interval
from intervals import Interval
import intervals.Interval
The primary interval class is directly importable from the top-level package.

Demonstrates how to create `Interval` objects using factory methods and directly, and how to perform a basic containment check. Note that rich interval operations (like `overlaps`, `intersection`, `union`) might be less intuitive or require manual implementation with this older, unmaintained library compared to modern alternatives.

from intervals import Interval, IntInterval # Create an interval using the factory method i1 = Interval.closed(1, 5) # Represents [1, 5] print(f"Interval i1: {i1}") # Create a half-open interval i2 = Interval.closedopen(5, 10) # Represents [5, 10) print(f"Interval i2: {i2}") # Create a specific type of interval (e.g., integer interval) i3 = IntInterval(3, 7) # Represents [3, 7] print(f"Interval i3: {i3}") # Check for containment print(f"4 in i1: {4 in i1}") # Expected: True print(f"5 in i2: {5 in i2}") # Expected: True print(f"10 in i2: {10 in i2}") # Expected: False # Check for overlap (note: older versions might not have a direct 'overlaps' method, requiring manual check or utility functions) # For simple overlap, you might compare bounds manually or use set operations if applicable # Or, rely on a library like 'portion' for richer operations.
Debug
Known issues
breakingThis library (`intervals` by kvesteri, version 0.9.2) is unmaintained and has not seen updates since 2016. It is highly recommended to use a currently maintained alternative, such as `portion` (which is a successor to a related library `python-intervals`), `pyinterval`, or `intervaltree` for better support, features, and Python version compatibility.
fix
Migrate to `portion` (pip install portion) or `intervaltree` (pip install intervaltree).
affects: <=0.9.2
gotchaAttempting to create a fully open, degenerate interval (e.g., `(a..a)`) will result in a `ValueError`. Both endpoints may be equal only if at least one of the bounds is closed (e.g., `[a..a]`, `[a..a)`, `(a..a]`).
fix
Ensure that if the lower and upper bounds are identical, at least one of the interval's boundaries is closed. For example, use `Interval.closed(a, a)` for a singleton or `Interval.closedopen(a, a)` for an empty interval with one closed bound.
affects: 0.9.x
gotchaThe `Interval()` constructor acts as a factory, attempting to guess the best matching interval subtype (e.g., `IntInterval`, `DateInterval`) based on the provided bounds. While convenient, this auto-detection can sometimes be slower or lead to unexpected types. For performance and clarity, directly instantiating specific interval types (e.g., `IntInterval(1, 5)`) is recommended if the type is known.
fix
Explicitly import and use specialized interval classes like `IntInterval`, `FloatInterval`, `DateInterval`, `DateTimeInterval` when working with known data types, rather than relying solely on the generic `Interval()` factory.
affects: 0.9.x
Errors
Common errors & fixes
TypeError: 'Interval' object is not iterable
Attempting to directly iterate over an `Interval` object as if it were a sequence of numbers (e.g., `for x in my_interval:`). The `Interval` object represents a range, not a collection of discrete values for iteration.
fix
If you need to iterate over discrete values within an interval, you must explicitly generate them (e.g., using `range()` for integer intervals) or convert the interval to a list of its atomic components if it's an `IntervalSet` (though this library's `Interval` class is not a set of points). For `portion` (a recommended alternative), you can use `P.open(1, 5).iterate(int)`.
ValueError: Invalid interval: upper bound must be greater than or equal to lower bound if both bounds are open.
This error occurs when trying to create an interval like `(5, 5)`, where both bounds are open and equal, which implies an empty interval that cannot contain any number, and is considered an invalid construction by this library.
fix
To represent an empty interval with equal bounds, ensure at least one bound is closed, e.g., `Interval.closedopen(5, 5)` or `Interval.openclosed(5, 5)` will correctly yield an empty interval. For a singleton, use `Interval.closed(5, 5)`.
AttributeError: 'Interval' object has no attribute 'overlaps'
This specific error indicates that the `intervals` library (kvesteri's) in version 0.9.x might not provide a direct `overlaps` method on the `Interval` object itself, unlike some other interval libraries (e.g., `portion` or `pyinterval`). Users often expect such methods based on experience with other libraries or common interval logic.
fix
To check for overlap with this library, you would typically need to implement the logic manually by comparing the bounds of the two intervals (e.g., `max(interval1.lower, interval2.lower) < min(interval1.upper, interval2.upper)` considering open/closed bounds). Alternatively, consider migrating to a more feature-rich library like `portion` which provides a dedicated `overlaps()` method.
Upgrade
Version history
0.9.2latest on PyPI · released Jul 2, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
intervals — pip install intervals · libregistry