diff --git a/src/wfdb/io/record.py b/src/wfdb/io/record.py index 21a12b98..c2c42981 100644 --- a/src/wfdb/io/record.py +++ b/src/wfdb/io/record.py @@ -2083,7 +2083,7 @@ def multi_to_single(self, physical, return_res=64, expanded=False): for field in fields: setattr(record, field, fields[field]) record.source_segments = source_segments - setattr(record, sig_attr, combined_signal) + _LoadedSignalValues(combined_signal, physical, expanded).set_on_record(record) # Use the signal to set record features if physical: diff --git a/tests/test_record_signal_modes.py b/tests/test_record_signal_modes.py index f878d674..4e6e551f 100644 --- a/tests/test_record_signal_modes.py +++ b/tests/test_record_signal_modes.py @@ -1,4 +1,4 @@ -"""Loaded signal value layouts for single-segment reads.""" +"""Loaded signal value layouts for single and multi-segment reads.""" import numpy as np import pytest @@ -35,6 +35,34 @@ def test_multifrequency_record_uses_one_signal_field(physical, expanded): assert values.dtype == f"{'float' if physical else 'int'}32" +@pytest.mark.parametrize("physical", [False, True]) +@pytest.mark.parametrize("expanded", [False, True]) +def test_flattened_multisegment_record_uses_one_signal_field(physical, expanded): + """Combining segments preserves the selected value mode and frame count.""" + record = wfdb.rdrecord( + "sample-data/multi-segment/fixed1/v102s", + sampfrom=74999, + sampto=75001, + physical=physical, + smooth_frames=not expanded, + return_res=32, + ) + field = ("e_" if expanded else "") + ("p_signal" if physical else "d_signal") + fields = ("p_signal", "d_signal", "e_p_signal", "e_d_signal") + + assert (record.sig_len, record.n_sig) == (2, 4) + assert [name for name in fields if getattr(record, name) is not None] == [field] + values = getattr(record, field) + if expanded: + assert [len(signal) for signal in values] == [2] * 4 + assert all( + signal.dtype == f"{'float' if physical else 'int'}32" for signal in values + ) + else: + assert values.shape == (2, 4) + assert values.dtype == f"{'float' if physical else 'int'}32" + + @pytest.mark.parametrize("smooth_frames", [False, True]) def test_physical_values_keep_missing_samples_after_skew(smooth_frames): """Digital missing markers become NaNs while other values are calibrated."""