Skip to content

Add readable aliases for Record signal arrays - #815

Merged
tompollard merged 3 commits into
mainfrom
record-signal-names
Dec 1, 2026
Merged

tompollard merged 3 commits into
mainfrom
record-signal-names

Conversation

@tompollard

@tompollard tompollard commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Add readable names for the four signal arrays on Record:

Existing New alias Layout
p_signal physical_signals uniform 2D
d_signal digital_signals uniform 2D
e_p_signal expanded_physical_signals per-channel 1D
e_d_signal expanded_digital_signals per-channel 1D

The aliases share the existing values; they do not create a second copy or change how Record reads and writes. The constructor accepts either spelling and rejects both spellings for the same form. Several forms can still coexist on one Record, and read_signals remains the choice when a caller wants exactly one explicit representation.

Assignments through the new names validate array shape and dtype. Expanded tuples are accepted and stored as lists of the same arrays for compatibility with the existing writer. Direct assignments through the legacy fields retain their behavior.

This follows the names proposed in #672 and complements the explicit return types already added for #376.

The docs also map legacy rdrecord/rdsamp options to read_signals and show how to get a single channel as a 1D array. The result container stays consistent when one channel is selected. read_signals always combines segments; callers who need an uncombined MultiRecord can use read_record(combine_segments=False).

Checks

  • 44 focused signal value tests passed, covering all four forms, invalid assignments, constructor conflicts, copies, pickling, metadata, writing, and single-channel shapes.
  • Ruff check and format check passed.
  • Sphinx documentation built with warnings as errors.

@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. The four aliases follow #672, share their arrays with the existing names, take keyword-only constructor arguments, and reject both spellings for the same form. The corrected p_signal/d_signal docstring (both forms can coexist, and the writer prefers digital) is a good fix. The single-channel recipes and option table address what #376 needed. The offline suite, Ruff and the strict docs build pass locally.

One consistency point: n_signals, n_frames, samples_per_frame, formats, channels and the annotation aliases all validate assignments through the new spelling, but these four store anything and fail only at write time. physical_signals = [[1.0, 2.0]] or a 1D array gives p_signal must be a two-dimensional array on write, a 2D array for expanded_physical_signals gives e_p_signal must be a sequence of channel arrays, and a float array for digital_signals gives the legacy TypeError: Field 'd_signal' must have a dtype that subclasses <class 'numpy.integer'>. Could the new setters (and constructor keywords) check for None or a 2D numeric array for the uniform forms (integer for digital_signals), and a list or tuple of 1D arrays for the expanded forms, leaving the legacy names unchanged?

Optional, for the option table: a row for sampfrom/sampto → start/stop (likely the most common translation), and a note that channels, channel_names and ignore_skew keep their names. It may also help to say that a record's expanded arrays are lists while read_signals returns a tuple.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks, I agree about validating assignments through the new names. I pushed b656dda:

  • Uniform aliases now accept None or a 2D NumPy array with the appropriate dtype: floating for physical values, integer for digital values.
  • Expanded aliases accept None or a list/tuple of 1D arrays with the appropriate dtype. A tuple is stored as a list of the same arrays because the existing writer requires a list. Legacy-field assignments retain their behavior.
  • The docs table now includes sampfrom/sampto → start/stop, notes the unchanged options, and explains the list versus tuple distinction.

I added tests for invalid constructor and setter values, unchanged legacy assignments, and writing after tuple input. The 44 focused tests, Ruff, and the strict docs build pass locally.

@tompollard
tompollard merged commit 8a87261 into main Dec 1, 2026
19 checks passed
@tompollard
tompollard deleted the record-signal-names branch December 1, 2026 02:55
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