Skip to content

Commit 4f6b841

Browse files
authored
Linter: Check condition IDs are unique (#92)
Closes #70
1 parent f6fd489 commit 4f6b841

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

petab/lint.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def check_condition_df(
108108

109109
check_ids(df.index.values, kind='condition')
110110

111+
if not df.index.is_unique:
112+
raise AssertionError("Non-unique condition IDs: "
113+
f"{df.index.values[df.index.duplicated()]}")
114+
111115
for column_name in req_cols:
112116
if not np.issubdtype(df[column_name].dtype, np.number):
113117
assert_no_leading_trailing_whitespace(

tests/test_lint.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,36 @@ def test_check_observable_df():
494494
bad_observable_df.index = ['obs1', 'obs1']
495495
with pytest.raises(AssertionError):
496496
lint.check_observable_df(bad_observable_df)
497+
498+
499+
def test_condition_ids_are_unique():
500+
condition_df = pd.DataFrame(data={
501+
CONDITION_ID: ['condition1', 'condition1'],
502+
'parameter1': [1.0, 2.0]
503+
})
504+
condition_df.set_index(CONDITION_ID, inplace=True)
505+
506+
with pytest.raises(AssertionError):
507+
lint.check_condition_df(condition_df)
508+
509+
condition_df.index = ['condition0', 'condition1']
510+
condition_df.index.name = 'conditionId'
511+
lint.check_condition_df(condition_df)
512+
513+
514+
def test_parameter_ids_are_unique():
515+
parameter_df = pd.DataFrame({
516+
PARAMETER_ID: ['par0', 'par0'],
517+
PARAMETER_SCALE: [LIN, LIN],
518+
ESTIMATE: [1, 1],
519+
LOWER_BOUND: [1e-5, 1e-6],
520+
UPPER_BOUND: [1e5, 1e6]
521+
522+
}).set_index(PARAMETER_ID)
523+
524+
with pytest.raises(AssertionError):
525+
lint.check_parameter_df(parameter_df)
526+
527+
parameter_df.index = ['par0', 'par1']
528+
parameter_df.index.name = 'parameterId'
529+
lint.check_parameter_df(parameter_df)

0 commit comments

Comments
 (0)