diff --git a/modelskill/matching.py b/modelskill/matching.py index 82cb58841..a00e8ed88 100644 --- a/modelskill/matching.py +++ b/modelskill/matching.py @@ -1,6 +1,5 @@ from __future__ import annotations -import warnings from datetime import timedelta from pathlib import Path from typing import ( @@ -361,7 +360,7 @@ def match_space_time( observation = observation.trim(period.start, period.end) - data = observation.data + data = observation.data.copy() data.attrs["name"] = observation.name data = data.rename({observation.name: "Observation"}) @@ -369,11 +368,12 @@ def match_space_time( # TODO is `align` the correct name for this operation? aligned = mr.align(observation, max_gap=max_model_gap) - if overlapping_names := set(aligned.data_vars) & set(data.data_vars): - warnings.warn( - "Model result has overlapping variable names with observation. Renamed with suffix `_model`." + if overlapping := set(aligned.filter_by_attrs(kind="aux").data_vars) & set( + observation.data.filter_by_attrs(kind="aux").data_vars + ): + raise ValueError( + f"Aux variables are not allowed to have identical names. Choose either aux from obs or model. Overlapping: {overlapping}" ) - aligned = aligned.rename({v: f"{v}_mod" for v in overlapping_names}) for dv in aligned: data[dv] = aligned[dv] diff --git a/tests/test_match.py b/tests/test_match.py index 5a2fe3c87..67cc873e1 100644 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -444,10 +444,8 @@ def test_obs_and_mod_can_not_have_same_aux_item_names(): obs = ms.PointObservation(obs_df, item="wl", aux_items=["wind_speed"]) mod = ms.PointModelResult(mod_df, item="wl", aux_items=["wind_speed"]) - with pytest.warns(match="_model"): - cmp = ms.match(obs=obs, mod=mod) - assert "wind_speed" in cmp - assert "wind_speed_mod" in cmp # renamed + with pytest.raises(ValueError, match="aux"): + ms.match(obs=obs, mod=mod) def test_mod_aux_items_overlapping_names(): @@ -474,7 +472,7 @@ def test_mod_aux_items_overlapping_names(): mod2_df, item="wl", aux_items=["wind_speed"], name="remote" ) - # we don't care which model the aux data comes from + # we don't care which model the aux data comes from, last one wins cmp = ms.match(obs=obs, mod=[mod, mod2]) assert "wind_speed" in cmp