Interval#

class Interval#

Immutable object implementing an Interval.

Example#

import pandasCore as pd

# Create Interval
obj = pd.Interval(...)

Attributes#

Attribute

Description

Example

closed

String describing the inclusive side of the interval.

View

closed_left

Check if the interval is closed on the left side.

View

closed_right

Check if the interval is closed on the right side.

View

is_empty

Check if the interval is empty.

left

Left bound for the interval.

View

length

Return the length of the interval.

View

mid

Return the midpoint of the interval.

View

right

Right bound for the interval.

View

Construction#

Method

Description

Example

__init__() (*args, **kwargs) | () | (left: typing.SupportsFloat, right: typing.SupportsFloat, closed: str = 'right')

Create a default interval (0, 0]

View

Comparison#

Method

Description

Example

__eq__() (other: pandasCore.Interval)

Check equality with another Interval.

__ge__() (other: pandasCore.Interval)

Greater than or equal comparison

__gt__() (other: pandasCore.Interval)

Greater than comparison

__le__() (other: pandasCore.Interval)

Less than or equal comparison

__lt__() (other: pandasCore.Interval)

Less than comparison (lexicographic by left, then right)

__ne__() (other: pandasCore.Interval)

Check inequality with another Interval

Iteration#

Method

Description

Example

__contains__() (item: typing.SupportsFloat)

Check if a value is contained in the interval.

Other Methods#

Method

Description

Example

__hash__() ()

Return a hash value for the Interval.

__repr__() ()

Return a string representation of the Interval.

__str__() ()

Return a string representation of the interval bounds.

overlaps() (other: pandasCore.Interval)

Check whether two Interval objects overlap.

Code Examples#

The following examples are extracted from the test suite.

closed (test_interval.py:37)
27def test_interval_constructor():
28    """Test Interval construction"""
29    f_print_header("Test: Interval Constructor")
30
31    try:
32        # Default constructor
33        iv = pandasCore.Interval(0, 5)
34        f_print_success("Created Interval(0, 5)")
35
36        # Check default closed is 'right'
37        if iv.closed == 'right':
38            f_print_success(f"Default closed is 'right': {iv.closed}")
39        else:
40            f_print_error(f"Expected closed='right', got '{iv.closed}'")
41            return False
42
43        # With explicit closed
44        iv_left = pandasCore.Interval(0, 5, closed='left')
45        if iv_left.closed == 'left':
46            f_print_success(f"Created Interval with closed='left'")
47        else:
closed_left (test_interval.py:108)
 98            return False
 99
100        # Test length
101        if iv.length == 6.0:
102            f_print_success(f"length property correct: {iv.length}")
103        else:
104            f_print_error(f"Expected length=6.0, got {iv.length}")
105            return False
106
107        # Test closed_left/closed_right
108        if not iv.closed_left:
109            f_print_success(f"closed_left is False for closed='right'")
110        else:
111            f_print_error(f"Expected closed_left=False for closed='right'")
112            return False
113
114        if iv.closed_right:
115            f_print_success(f"closed_right is True for closed='right'")
116        else:
117            f_print_error(f"Expected closed_right=True for closed='right'")
118            return False
closed_right (test_interval.py:114)
104            f_print_error(f"Expected length=6.0, got {iv.length}")
105            return False
106
107        # Test closed_left/closed_right
108        if not iv.closed_left:
109            f_print_success(f"closed_left is False for closed='right'")
110        else:
111            f_print_error(f"Expected closed_left=False for closed='right'")
112            return False
113
114        if iv.closed_right:
115            f_print_success(f"closed_right is True for closed='right'")
116        else:
117            f_print_error(f"Expected closed_right=True for closed='right'")
118            return False
119
120        return True
121
122    except Exception as e:
123        f_print_error(f"Exception: {e}")
124        return False
left (test_interval.py:80)
70def test_interval_properties():
71    """Test Interval properties"""
72    f_print_header("Test: Interval Properties")
73
74    try:
75        iv = pandasCore.Interval(2, 8, closed='right')
76
77        # Test left
78        if iv.left == 2.0:
79            f_print_success(f"left property correct: {iv.left}")
80        else:
81            f_print_error(f"Expected left=2.0, got {iv.left}")
82            return False
83
84        # Test right
85        if iv.right == 8.0:
86            f_print_success(f"right property correct: {iv.right}")
87        else:
88            f_print_error(f"Expected right=8.0, got {iv.right}")
length (test_interval.py:101)
 91            return False
 92
 93        # Test mid
 94        if iv.mid == 5.0:
 95            f_print_success(f"mid property correct: {iv.mid}")
 96        else:
 97            f_print_error(f"Expected mid=5.0, got {iv.mid}")
 98            return False
 99
100        # Test length
101        if iv.length == 6.0:
102            f_print_success(f"length property correct: {iv.length}")
103        else:
104            f_print_error(f"Expected length=6.0, got {iv.length}")
105            return False
106
107        # Test closed_left/closed_right
108        if not iv.closed_left:
109            f_print_success(f"closed_left is False for closed='right'")
110        else:
111            f_print_error(f"Expected closed_left=False for closed='right'")
mid (test_interval.py:94)
 84            return False
 85
 86        # Test right
 87        if iv.right == 8.0:
 88            f_print_success(f"right property correct: {iv.right}")
 89        else:
 90            f_print_error(f"Expected right=8.0, got {iv.right}")
 91            return False
 92
 93        # Test mid
 94        if iv.mid == 5.0:
 95            f_print_success(f"mid property correct: {iv.mid}")
 96        else:
 97            f_print_error(f"Expected mid=5.0, got {iv.mid}")
 98            return False
 99
100        # Test length
101        if iv.length == 6.0:
102            f_print_success(f"length property correct: {iv.length}")
103        else:
104            f_print_error(f"Expected length=6.0, got {iv.length}")
right (test_interval.py:87)
77        iv = pandasCore.Interval(2, 8, closed='right')
78
79        # Test left
80        if iv.left == 2.0:
81            f_print_success(f"left property correct: {iv.left}")
82        else:
83            f_print_error(f"Expected left=2.0, got {iv.left}")
84            return False
85
86        # Test right
87        if iv.right == 8.0:
88            f_print_success(f"right property correct: {iv.right}")
89        else:
90            f_print_error(f"Expected right=8.0, got {iv.right}")
91            return False
92
93        # Test mid
94        if iv.mid == 5.0:
95            f_print_success(f"mid property correct: {iv.mid}")
96        else:
97            f_print_error(f"Expected mid=5.0, got {iv.mid}")
__init__ (test_interval.py:33)
23import pandasCore
24import pandas as pd
25
26
27def test_interval_constructor():
28    """Test Interval construction"""
29    f_print_header("Test: Interval Constructor")
30
31    try:
32        # Default constructor
33        iv = pandasCore.Interval(0, 5)
34        f_print_success("Created Interval(0, 5)")
35
36        # Check default closed is 'right'
37        if iv.closed == 'right':
38            f_print_success(f"Default closed is 'right': {iv.closed}")
39        else:
40            f_print_error(f"Expected closed='right', got '{iv.closed}'")
41            return False
42
43        # With explicit closed