Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/semeio/fmudesign/_excel2dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions tests/fmudesign/test_excel2dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading