Skip to content

Expose segment roles and frame ranges on MultiRecord - #828

Merged
tompollard merged 2 commits into
mainfrom
api/segment-views
Dec 1, 2026
Merged

tompollard merged 2 commits into
mainfrom
api/segment-views

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Add MultiRecord.segment_views, a read-only snapshot of the current segment names, roles, and frame ranges. Each entry is a SegmentView(index, name, start, stop, kind) with n_frames available as a property. The roles are layout, gap, and data.

This lets callers inspect gap lengths and variable-layout headers without interpreting None entries in MultiRecord.segments. A non-gap segment stays data even when no selected channels caused its Record to be loaded. The existing mutable lists and segment objects remain unchanged. Combined Record.source_segments also gains kind and n_frames properties, so both return forms expose the same distinction.

This addresses the segment representation and provenance questions in #746. The separate header-only channel view is in #827.

Checks

  • uv run pytest tests/test_segment_views.py tests/test_read_record.py tests/test_source_provenance.py -q -m 'not network' (79 passed)
  • uv run pytest -m 'not network' -q (1578 passed, 4 skipped, 23 deselected)
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run --only-group docs make -C docs html SPHINXOPTS='-W --keep-going'

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. segment_views reads clearly and fixes a real ambiguity: on s25047 it labels the layout header, gaps and data correctly from both rdheader and a selected read_record, an unloaded data segment stays "data", and the offsets match the combined record's source_segments. The offline suite, Ruff and the strict docs build pass locally.

Two suggestions:

  • Use layout when it's known. kind is "layout" for any first zero-length segment, so MultiRecord(seg_name=["a", "b"], seg_len=[0, 5], layout="fixed").segment_views gives ["layout", "data"]. Records read from files carry layout ("variable" for s25047), so checking self.layout == "variable" when set, and falling back to the position rule only when it's None, would be exact.
  • A clear error instead of None for mismatched lists. With seg_name=["a", "b"] and seg_len=[2], segment_views is None, and for view in multi.segment_views then fails with TypeError: 'NoneType' object is not iterable. Raising ValueError naming the mismatch would match the recent direction on clear errors. None could still mean "no segment lists at all".

Not for this PR: with SegmentReference (headers), SourceSegment (combined records) and now SegmentView (preserved records), it might be worth noting on #746 whether these should converge.

@tompollard

tompollard commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

Thanks. I changed segment_views to use the declared layout when it is set, falling back to a zero-length first segment only when layout is unknown. The new test covers fixed, variable and unknown layouts (0a95291).

I kept None for mismatched or incomplete segment lists. These fields are mutable, and callers may update them in separate steps; raising from a property would also make hasattr, getattr and inspection tools fail during that edit, as we avoided with Record.metadata. The docs now tell callers to check for None when working with manually constructed records. Valid records read from files have aligned lists, so iteration works directly.

I agree the three descriptor types merit a separate look and will note that on #746. The focused tests (11 passed), Ruff and the strict docs build pass.

@tompollard
tompollard merged commit 95022e1 into main Dec 1, 2026
19 checks passed
@tompollard
tompollard deleted the api/segment-views branch December 1, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant