Interval ======== .. currentmodule:: pandasCore .. class:: Interval Immutable object implementing an Interval. Example ------- .. code-block:: python import pandasCore as pd # Create Interval obj = pd.Interval(...) Attributes ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Attribute - Description - Example * - :attr:`~Interval.closed` - String describing the inclusive side of the interval. - :ref:`View ` * - :attr:`~Interval.closed_left` - Check if the interval is closed on the left side. - :ref:`View ` * - :attr:`~Interval.closed_right` - Check if the interval is closed on the right side. - :ref:`View ` * - :attr:`~Interval.is_empty` - Check if the interval is empty. - * - :attr:`~Interval.left` - Left bound for the interval. - :ref:`View ` * - :attr:`~Interval.length` - Return the length of the interval. - :ref:`View ` * - :attr:`~Interval.mid` - Return the midpoint of the interval. - :ref:`View ` * - :attr:`~Interval.right` - Right bound for the interval. - :ref:`View ` Construction ------------ .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Interval.__init__` ``(*args, **kwargs) | () | (left: typing.SupportsFloat, right: typing.SupportsFloat, closed: str = 'right')`` - Create a default interval (0, 0] - :ref:`View ` Comparison ---------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Interval.__eq__` ``(other: pandasCore.Interval)`` - Check equality with another Interval. - * - :meth:`~Interval.__ge__` ``(other: pandasCore.Interval)`` - Greater than or equal comparison - * - :meth:`~Interval.__gt__` ``(other: pandasCore.Interval)`` - Greater than comparison - * - :meth:`~Interval.__le__` ``(other: pandasCore.Interval)`` - Less than or equal comparison - * - :meth:`~Interval.__lt__` ``(other: pandasCore.Interval)`` - Less than comparison (lexicographic by left, then right) - * - :meth:`~Interval.__ne__` ``(other: pandasCore.Interval)`` - Check inequality with another Interval - Iteration --------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Interval.__contains__` ``(item: typing.SupportsFloat)`` - Check if a value is contained in the interval. - Other Methods ------------- .. list-table:: :widths: 25 60 15 :header-rows: 1 * - Method - Description - Example * - :meth:`~Interval.__hash__` ``()`` - Return a hash value for the Interval. - * - :meth:`~Interval.__repr__` ``()`` - Return a string representation of the Interval. - * - :meth:`~Interval.__str__` ``()`` - Return a string representation of the interval bounds. - * - :meth:`~Interval.overlaps` ``(other: pandasCore.Interval)`` - Check whether two Interval objects overlap. - Code Examples ------------- The following examples are extracted from the test suite. .. _example-interval-closed-0: .. dropdown:: closed (test_interval.py:37) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 27 :emphasize-lines: 11 def test_interval_constructor(): """Test Interval construction""" f_print_header("Test: Interval Constructor") try: # Default constructor iv = pandasCore.Interval(0, 5) f_print_success("Created Interval(0, 5)") # Check default closed is 'right' if iv.closed == 'right': f_print_success(f"Default closed is 'right': {iv.closed}") else: f_print_error(f"Expected closed='right', got '{iv.closed}'") return False # With explicit closed iv_left = pandasCore.Interval(0, 5, closed='left') if iv_left.closed == 'left': f_print_success(f"Created Interval with closed='left'") else: .. _example-interval-closed_left-1: .. dropdown:: closed_left (test_interval.py:108) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 98 :emphasize-lines: 11 return False # Test length if iv.length == 6.0: f_print_success(f"length property correct: {iv.length}") else: f_print_error(f"Expected length=6.0, got {iv.length}") return False # Test closed_left/closed_right if not iv.closed_left: f_print_success(f"closed_left is False for closed='right'") else: f_print_error(f"Expected closed_left=False for closed='right'") return False if iv.closed_right: f_print_success(f"closed_right is True for closed='right'") else: f_print_error(f"Expected closed_right=True for closed='right'") return False .. _example-interval-closed_right-2: .. dropdown:: closed_right (test_interval.py:114) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 104 :emphasize-lines: 11 f_print_error(f"Expected length=6.0, got {iv.length}") return False # Test closed_left/closed_right if not iv.closed_left: f_print_success(f"closed_left is False for closed='right'") else: f_print_error(f"Expected closed_left=False for closed='right'") return False if iv.closed_right: f_print_success(f"closed_right is True for closed='right'") else: f_print_error(f"Expected closed_right=True for closed='right'") return False return True except Exception as e: f_print_error(f"Exception: {e}") return False .. _example-interval-left-3: .. dropdown:: left (test_interval.py:80) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 70 :emphasize-lines: 11 def test_interval_properties(): """Test Interval properties""" f_print_header("Test: Interval Properties") try: iv = pandasCore.Interval(2, 8, closed='right') # Test left if iv.left == 2.0: f_print_success(f"left property correct: {iv.left}") else: f_print_error(f"Expected left=2.0, got {iv.left}") return False # Test right if iv.right == 8.0: f_print_success(f"right property correct: {iv.right}") else: f_print_error(f"Expected right=8.0, got {iv.right}") .. _example-interval-length-4: .. dropdown:: length (test_interval.py:101) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 91 :emphasize-lines: 11 return False # Test mid if iv.mid == 5.0: f_print_success(f"mid property correct: {iv.mid}") else: f_print_error(f"Expected mid=5.0, got {iv.mid}") return False # Test length if iv.length == 6.0: f_print_success(f"length property correct: {iv.length}") else: f_print_error(f"Expected length=6.0, got {iv.length}") return False # Test closed_left/closed_right if not iv.closed_left: f_print_success(f"closed_left is False for closed='right'") else: f_print_error(f"Expected closed_left=False for closed='right'") .. _example-interval-mid-5: .. dropdown:: mid (test_interval.py:94) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 84 :emphasize-lines: 11 return False # Test right if iv.right == 8.0: f_print_success(f"right property correct: {iv.right}") else: f_print_error(f"Expected right=8.0, got {iv.right}") return False # Test mid if iv.mid == 5.0: f_print_success(f"mid property correct: {iv.mid}") else: f_print_error(f"Expected mid=5.0, got {iv.mid}") return False # Test length if iv.length == 6.0: f_print_success(f"length property correct: {iv.length}") else: f_print_error(f"Expected length=6.0, got {iv.length}") .. _example-interval-right-6: .. dropdown:: right (test_interval.py:87) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 77 :emphasize-lines: 11 iv = pandasCore.Interval(2, 8, closed='right') # Test left if iv.left == 2.0: f_print_success(f"left property correct: {iv.left}") else: f_print_error(f"Expected left=2.0, got {iv.left}") return False # Test right if iv.right == 8.0: f_print_success(f"right property correct: {iv.right}") else: f_print_error(f"Expected right=8.0, got {iv.right}") return False # Test mid if iv.mid == 5.0: f_print_success(f"mid property correct: {iv.mid}") else: f_print_error(f"Expected mid=5.0, got {iv.mid}") .. _example-interval-dunder-initdunder--7: .. dropdown:: __init__ (test_interval.py:33) :class-title: example-dropdown .. code-block:: python :linenos: :lineno-start: 23 :emphasize-lines: 11 import pandasCore import pandas as pd def test_interval_constructor(): """Test Interval construction""" f_print_header("Test: Interval Constructor") try: # Default constructor iv = pandasCore.Interval(0, 5) f_print_success("Created Interval(0, 5)") # Check default closed is 'right' if iv.closed == 'right': f_print_success(f"Default closed is 'right': {iv.closed}") else: f_print_error(f"Expected closed='right', got '{iv.closed}'") return False # With explicit closed