vayu.interval¶
interval
¶
Interval
dataclass
¶
A closed interval [start, end] with union / intersection / containment algebra.
Works on any comparable type — int, float, date, datetime.
Subclasses (e.g. TimeWindow) flow through operators automatically because
the dunder methods use self.__class__.
Single-point intervals (start == end) are allowed so that touching
endpoints like [1, 3] & [3, 5] produce [3, 3] instead of raising.
Attributes:
| Name | Type | Description |
|---|---|---|
start |
Comparable
|
Lower bound (inclusive). |
end |
Comparable
|
Upper bound (inclusive). |
intersection
¶
Return the overlapping sub-interval, or raise if there's no overlap.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the intervals don't overlap. |
Source code in vayu/interval.py
union
classmethod
¶
Return the smallest interval that contains all inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intervals
|
Sequence[Interval]
|
One or more intervals to union. |
required |
allow_gaps
|
bool
|
If False (the default), raise |
False
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
ValueError
|
If |