Interval¶
-
class
part.Interval(lower_value=None, upper_value=None, lower_closed=True, upper_closed=None)¶ Interval class.
The
Intervalclass (which inherits from theAtomicclass) is designed to hold range values. Allen’s interval algebra has been implemented.An interval can hold any type of value that implements a total order.
Each bound of the interval can be open or closed.
-
static
__new__(cls, lower_value=None, upper_value=None, lower_closed=True, upper_closed=None)¶ Create an
Atomicinstance.- Keyword Arguments
- Returns
- Raises
ValueError – If
lower_valueis not comparable withupper_value.
See also
__init__For interval initialization.
Examples
>>> from part import Interval >>> a = Interval[int](lower_value=10, upper_value=0) >>> bool(a) False
-
__init__(lower_value=None, upper_value=None, lower_closed=True, upper_closed=None)¶ Initialize an
Intervalinstance.By default, an interval is closed to the left and open to the right.
- Keyword Arguments
See also
__new__For detection of empty interval creation.
Examples
>>> from part import Interval >>> print(Interval[int](lower_value=10, upper_value=20)) [10;20) >>> print(Interval[str](lower_value="abc", upper_value="def", ... upper_closed=True)) ['abc';'def'] >>> print(Interval[int](lower_closed=None, lower_value=10, upper_value=20)) (10;20) >>> print(Interval[int]()) (-inf;+inf)
-
__str__()¶ Return str(self).
-
__eq__(other)¶ Return self==other.
-
__lt__(other)¶ Comparison using Allen’s algebra.
- Parameters
other (
Atomic) – Another atomic value.- Returns
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> a < Atomic[int].from_tuple((25, 30)) True
-
__gt__(other)¶ Comparison using Allen’s algebra.
- Parameters
other (
Atomic) – Another atomic value.- Returns
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> a > Atomic[int].from_tuple((25, 30)) False
-
__hash__()¶ Return hash(self).
-
__or__(other)¶ Compute the union of two intervals.
- Parameters
other (
Atomic) – Another atomic value.- Returns
The union of the interval and the other.
- Return type
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> b = Atomic[int].from_tuple((15, 30)) >>> c = Atomic[int].from_tuple((30, 40)) >>> print(a | b) (10;30) >>> print(a | c) (10;20) | [30;40)
-
__and__(other)¶ Compute the intersection of two intervals.
- Parameters
other (
Atomic) – Another atomic value.- Returns
The intersection of the interval and the other.
- Return type
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> b = Atomic[int].from_tuple((15, 30)) >>> c = Atomic[int].from_tuple((30, 40)) >>> print(a & b) [15;20) >>> print(a & c)
-
__sub__(other)¶ Compute the difference of two intervals.
- Parameters
other (
Atomic) – Another atomic value.- Returns
The difference between the interval and the other.
- Return type
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> b = Atomic[int].from_tuple((15, 30)) >>> c = Atomic[int].from_tuple((30, 40)) >>> print(a - b) (10;15) >>> print(a - c) (10;20)
-
__xor__(other)¶ Compute the symmetric difference of two intervals.
- Parameters
other (
Atomic) – Another atomic value.- Returns
The symmetric difference between the interval and the other.
- Return type
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> b = Atomic[int].from_tuple((15, 30)) >>> c = Atomic[int].from_tuple((30, 40)) >>> print(a ^ b) (10;15) | [20;30) >>> print(a ^ c) (10;20) | [30;40)
-
__invert__()¶ Compute the complement of the interval.
- Returns
The complement of the interval.
- Return type
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> print(~a) (-inf;10] | [20;+inf)
-
static
upper_limit(value=None, closed=None)¶ Create an interval from an upper limit.
- Parameters
- Returns
An interval with an upper limit.
- Return type
Examples
>>> from part import Interval >>> print(Interval[int].upper_limit(value=10)) (-inf;10) >>> print(Interval[int].upper_limit(value=10, closed=True)) (-inf;10]
-
static
lower_limit(value=None, closed=True)¶ Create an interval from a lower limit.
- Parameters
- Returns
An interval with a lower limit.
- Return type
Examples
>>> from part import Interval >>> print(Interval[int].lower_limit(value=10)) [10;+inf) >>> print(Interval[int].lower_limit(value=10, closed=None)) (10;+inf)
-
before(other, strict=True, reverse=False)¶ Return
Trueif the subset is the before the other.- Parameters
- Raises
NotImplementedError – if the method is not implemented in the class.
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> a.before(Atomic[int].from_tuple((25, 30))) True
-
meets(other, strict=True, reverse=False)¶ Return
Trueif the subset meets the other.- Parameters
- Raises
NotImplementedError – if the method is not implemented in the class.
Examples
>>> from part import Atomic >>> a = Atomic.from_tuple((10, 20, None)) >>> a.meets(Atomic[int].from_tuple((20, 30))) False >>> a.meets(Atomic[int].from_tuple((20, 30)), strict=False) True
-
overlaps(other, strict=True, reverse=False)¶ Return
Trueif the subset overlaps the other.- Parameters
- Raises
NotImplementedError – if the method is not implemented in the class.
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> a.overlaps(Atomic[int].from_tuple((15, 30))) True
-
starts(other, strict=True, reverse=False)¶ Return
Trueif the subset starts the other.- Parameters
- Raises
NotImplementedError – if the method is not implemented in the class.
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> a.starts(Atomic[int].from_tuple((20, 40, None))) False >>> a.starts(Atomic[int].from_tuple((10, 40, None)), strict=False) True
-
during(other, strict=True, reverse=False)¶ Return
Trueif the subset is during the other.- Parameters
- Raises
NotImplementedError – if the method is not implemented in the class.
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> a.during(Atomic[int].from_tuple((0, 30))) True
-
finishes(other, strict=True, reverse=False)¶ Return
Trueif the subset finishes the other.- Parameters
- Raises
NotImplementedError – if the method is not implemented in the class.
Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> a.finishes(Atomic[int].from_tuple((0, 20))) True
-
property
lower¶ Get the
lowerproperty.Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> print(a.lower) 10+
-
property
lower_value¶ Get the
lower_valueproperty.Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> print(a.lower_value) 10
-
property
lower_closed¶ Get the
lower_closedproperty.Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> print(a.lower_closed) None
-
property
upper¶ Get the
upperproperty.Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> print(a.upper) 20-
-
property
upper_value¶ Get the
lower_valueproperty.Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> print(a.upper_value) 20
-
property
upper_closed¶ Get the
upper_closedproperty.Examples
>>> from part import Atomic >>> a = Atomic[int].from_tuple((10, 20, None)) >>> print(a.upper_closed) None
-
static