Repository navigation
Add readable aliases for Record signal arrays - #815
Conversation
tompollard
left a comment
There was a problem hiding this comment.
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.
|
Thanks, I agree about validating assignments through the new names. I pushed b656dda:
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. |
Summary
Add readable names for the four signal arrays on
Record:p_signalphysical_signalsd_signaldigital_signalse_p_signalexpanded_physical_signalse_d_signalexpanded_digital_signalsThe aliases share the existing values; they do not create a second copy or change how
Recordreads and writes. The constructor accepts either spelling and rejects both spellings for the same form. Several forms can still coexist on oneRecord, andread_signalsremains 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/rdsampoptions toread_signalsand show how to get a single channel as a 1D array. The result container stays consistent when one channel is selected.read_signalsalways combines segments; callers who need an uncombinedMultiRecordcan useread_record(combine_segments=False).Checks