From e281772619906d44c89981d49d0472841ce46a4a Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:30:06 +0000 Subject: [PATCH] Reject duplicate explicit TimeSeries signal names Fixes #3967. --- python/mujoco/sysid/_src/timeseries.py | 4 ++++ python/mujoco/sysid/tests/test_timeseries.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/python/mujoco/sysid/_src/timeseries.py b/python/mujoco/sysid/_src/timeseries.py index 64ab9e7d618..010d1f4e567 100644 --- a/python/mujoco/sysid/_src/timeseries.py +++ b/python/mujoco/sysid/_src/timeseries.py @@ -101,6 +101,8 @@ def _resolve_signals( ) canon_name, sig_type, width = resolved + if canon_name in result: + raise ValueError(f"Duplicate signal name '{canon_name}'.") result[canon_name] = (sig_type, np.arange(idx, idx + width)) idx += width @@ -343,6 +345,8 @@ def from_custom_map( f"Signal '{name}' must have positive width, got {width}." ) + if name in signal_mapping_dict: + raise ValueError(f"Duplicate signal name '{name}'.") indices = np.arange(current_index, current_index + width) signal_mapping_dict[name] = (sig_type, indices) current_index += width diff --git a/python/mujoco/sysid/tests/test_timeseries.py b/python/mujoco/sysid/tests/test_timeseries.py index c5c8f4ac7dc..e544dad07af 100644 --- a/python/mujoco/sysid/tests/test_timeseries.py +++ b/python/mujoco/sysid/tests/test_timeseries.py @@ -265,6 +265,11 @@ def test_from_model_controls_explicit_names(): assert ts.signal_mapping is not None assert "m1_ctrl" in ts.signal_mapping + with pytest.raises(ValueError, match="Duplicate signal name"): + TimeSeries.from_control_names( + times, np.zeros((10, 2)), model, names=["m1", "m1_ctrl"] + ) + with pytest.raises(ValueError, match="Could not resolve signal"): TimeSeries.from_control_names(times, data, model, names=["invalid"]) @@ -326,6 +331,14 @@ def test_from_model_state_resolution(): assert "j2_qpos" in ts.signal_mapping +def test_duplicate_custom_signal_names(): + """Duplicated names must not silently discard a data column.""" + with pytest.raises(ValueError, match="Duplicate signal name"): + TimeSeries.from_custom_map( + np.array([0.0, 1.0]), np.zeros((2, 2)), ["a", "a"] + ) + + def test_from_custom(): """Custom signal definitions (name strings and dimension tuples) are mapped correctly.""" times = np.linspace(0, 1, 10)