diff --git a/src/semeio/fmudesign/_excel2dict.py b/src/semeio/fmudesign/_excel2dict.py index 8d84332eb..95f4d96ac 100644 --- a/src/semeio/fmudesign/_excel2dict.py +++ b/src/semeio/fmudesign/_excel2dict.py @@ -168,18 +168,18 @@ def _find_onebyone_input_sheet(input_filename: str) -> str: def _check_designinput(dsgn_input: pd.DataFrame) -> None: """Checks for valid input in designinput sheet""" + # Filter out rows where sensname has no value + valid_sensnames = dsgn_input["sensname"].dropna() + duplicated_mask = valid_sensnames.duplicated() - # Check for duplicate sensnames - sensitivity_names = [] - for row in dsgn_input.itertuples(): - if _has_value(row.sensname): - if row.sensname in sensitivity_names: - raise ValueError( - f"sensname '{row.sensname}' was found on more than one row in designinput " - "sheet. Two sensitivities can not share the same sensname. " - "Please correct this and rerun" - ) - sensitivity_names.append(row.sensname) + if duplicated_mask.any(): + # Find the first duplicate to include in error message + duplicate_name = valid_sensnames[duplicated_mask].iloc[0] + raise ValueError( + f"sensname '{duplicate_name}' was found on more than one row in designinput " + "sheet. Two sensitivities can not share the same sensname. " + "Please correct this and rerun" + ) def _check_for_mixed_sensitivities(sens_name: str, sens_group: pd.DataFrame) -> None: diff --git a/tests/fmudesign/test_excel2dict.py b/tests/fmudesign/test_excel2dict.py index be71a73d1..2f55c7a82 100644 --- a/tests/fmudesign/test_excel2dict.py +++ b/tests/fmudesign/test_excel2dict.py @@ -87,6 +87,9 @@ def test_duplicate_sensname_exception(tmpdir, monkeypatch): ["sensname", "numreal", "type", "param_name"], ["rms_seed", "", "seed"], ["rms_seed", "", "seed"], + [np.nan, "", "seed"], # NaN sensname - should be ignored + ["", "", "seed"], # Empty string - should be ignored + ["valid_name", "", "seed"], # Valid unique name ] ) monkeypatch.chdir(tmpdir)