diff --git a/cellpy/readers/instruments/base.py b/cellpy/readers/instruments/base.py index 8f42fa5f..77fff332 100644 --- a/cellpy/readers/instruments/base.py +++ b/cellpy/readers/instruments/base.py @@ -851,7 +851,7 @@ def parse_loader_parameters(self, auto_formatter=None, **kwargs): if unit_labels := kwargs.get("unit_labels", None): logging.critical(f"overriding unit_labels: {unit_labels}") - self.config_params.raw_limits.update(unit_labels) + self.config_params.unit_labels.update(unit_labels) if raw_limits := kwargs.get("raw_limits", None): logging.critical(f"overriding raw_limits: {raw_limits}") diff --git a/tests/test_loader_two_stage.py b/tests/test_loader_two_stage.py index 39268682..982d66cb 100644 --- a/tests/test_loader_two_stage.py +++ b/tests/test_loader_two_stage.py @@ -132,3 +132,29 @@ def test_the_two_stages_agree_with_the_legacy_frame(): f"{column} differs by {difference} between the two-stage path and " f"the legacy path" ) + + +@pytest.mark.essential +def test_unit_labels_override_lands_in_unit_labels_not_raw_limits(): + """A ``unit_labels=`` override must reach ``config_params.unit_labels``. + + Regression for a copy-paste slip where the ``unit_labels`` branch of + ``parse_loader_parameters`` updated ``raw_limits`` instead. The symptom was + that vendor column-name templates (neware spells its columns + ``Current({{ current }})``) could not be overridden this way, while the + unit-label strings silently polluted ``raw_limits``. + """ + loader = _loader("neware_txt", model="one") + raw_limits_before = dict(loader.config_params.raw_limits) + + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + # sep is given so the branch runs without touching the auto-formatter. + loader.parse_loader_parameters(sep="\t", unit_labels={"current": "A"}) + + assert loader.config_params.unit_labels["current"] == "A", ( + "unit_labels override did not reach config_params.unit_labels" + ) + assert dict(loader.config_params.raw_limits) == raw_limits_before, ( + "unit_labels override leaked into config_params.raw_limits" + )