{"id":9826,"library":"igwn-segments","title":"IGWN Segments","description":"IGWN Segments (igwn-segments) provides a robust Pythonic representation of half-open intervals and lists of such intervals. It offers tools for creating, manipulating, and performing set-like operations (union, intersection, subtraction) on time segments, crucial for gravitational-wave data analysis and other scientific applications. Currently at version 2.1.1, the library follows an irregular release cadence, driven by the needs of the IGWN collaboration.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"https://github.com/igwn-segments/segments","tags":["intervals","time-series","data-analysis","scientific-computing","astronomy","gravitational-wave"],"install":[{"cmd":"pip install igwn-segments","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Fundamental array operations and data structures.","package":"numpy","optional":false},{"reason":"Used for parsing segment strings.","package":"lark","optional":false},{"reason":"Used for advanced segment list operations.","package":"scipy","optional":false}],"imports":[{"symbol":"Segment","correct":"from segments import Segment"},{"symbol":"SegmentList","correct":"from segments import SegmentList"}],"quickstart":{"code":"from segments import Segment, SegmentList\n\n# Create individual segments\ns1 = Segment(100.0, 200.0)\ns2 = Segment(150.0, 250.0)\ns3 = Segment(300.0, 350.0)\n\nprint(f\"Segment 1: {s1}\")\nprint(f\"Segment 2: {s2}\")\nprint(f\"Duration of s1: {s1.duration}\")\nprint(f\"s1 intersects s2: {s1.intersects(s2)}\")\n\n# Create a list of segments\nsl = SegmentList([s1, s2, s3])\nprint(f\"Initial SegmentList: {sl}\")\n\n# Perform union operation\nunion_sl = sl.union()\nprint(f\"Union of SegmentList: {union_sl}\")\n\n# Add a segment to a SegmentList\nsl_plus_s4 = sl.union(Segment(0, 50))\nprint(f\"SegmentList with an added segment: {sl_plus_s4}\")\n\n# Create from string representation\nsl_from_str = SegmentList.from_str('[[10, 20), [30, 40))')\nprint(f\"SegmentList from string: {sl_from_str}\")","lang":"python","description":"This quickstart demonstrates how to create `Segment` and `SegmentList` objects, calculate durations, check for intersections, and perform union operations. It also shows how to create a `SegmentList` from a string representation."},"warnings":[{"fix":"Review code that assumed or explicitly set `is_right_open`. Adjust interval definitions if previous code relied on closed or open intervals in different ways. Ensure all custom interval parsing aligns with the `[start, end)` convention.","message":"As of v2.0.0, `Segment` and `SegmentList` objects strictly represent half-open intervals `[start, end)`. The `segments.Segment.is_right_open` parameter has been removed, and intervals are always right-open.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always assign the result of `SegmentList` operations to a new variable or reassign to the original variable. For example: `my_segment_list = my_segment_list.union(new_segment)`.","message":"Individual `Segment` objects are immutable. Operations like `union()`, `intersection()`, or `subtraction()` on a `SegmentList` return a *new* `SegmentList` object. Attempting to modify a `Segment` in place will fail.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Replace `segment1 + segment2` with `SegmentList([segment1, segment2]).union()` (or similar for other operations and existing `SegmentList` objects). For example, `segment_list.union(other_segment_list)`.","message":"Direct arithmetic operators (`+`, `-`, `*`, `/`) are not defined for `Segment` objects or for performing set-like operations on `SegmentList` objects. Instead, use explicit methods like `.union()`, `.intersection()`, `.subtraction()`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Use the dedicated methods provided by `SegmentList` for set-like operations, such as `.union()`, `.intersection()`, or `.subtraction()`. Example: `SegmentList([s1, s2]).union()`","cause":"Attempting to use Python's `+` operator for segment union, intersection, or other set-like operations.","error":"TypeError: unsupported operand type(s) for +: 'Segment' and 'Segment'"},{"fix":"Ensure the string format strictly adheres to the library's expectations for half-open intervals, typically `[start, end)` for single segments and `[[start1, end1), [start2, end2))` for lists. For example: `SegmentList.from_str('[[10, 20), [30, 40))')`.","cause":"The string representation passed to `Segment.from_str()` or `SegmentList.from_str()` does not conform to the expected syntax, typically due to incorrect bracket usage or missing commas.","error":"ValueError: Invalid segment string format: '[[10,20], [30,40]]' (or similar)"},{"fix":"Ensure that methods for combining or manipulating multiple segments are called on a `SegmentList`. If you have a single segment and want to combine it with others, first wrap it in a `SegmentList`: `SegmentList([my_segment]).union(other_list)`.","cause":"Attempting to call a list-oriented method like `union()` directly on a single `Segment` object instead of a `SegmentList` object.","error":"AttributeError: 'Segment' object has no attribute 'union'"}]}