Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator: check datasetId in visualizations table exists in measurem… #255

Merged
merged 1 commit into from
Apr 19, 2024
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
Validator: check datasetId in visualizations table exists in measurem…
…ents table

Closes #229
  • Loading branch information
dweindl committed Apr 19, 2024
commit eb3143bb84cdd043ef9ca294396114053877eebd
14 changes: 14 additions & 0 deletions petab/visualize/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ def validate_visualization_df(problem: Problem) -> bool:
)
errors = True

if problem.measurement_df is not None:
referenced_datasets = set(filter(bool, vis_df[C.DATASET_ID].unique()))
if referenced_datasets:
existing_datasets = set(
filter(bool, problem.measurement_df[C.DATASET_ID].unique())
)
if not referenced_datasets.issubset(existing_datasets):
logger.error(
f"Visualization table references {C.DATASET_ID}(s) "
f"{referenced_datasets - existing_datasets}, but no such "
"dataset(s) exist in the measurement table."
)
errors = True

return errors


Expand Down
31 changes: 27 additions & 4 deletions tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,16 @@ def test_visualization_with_vis_and_sim(
simulation_file_Isensee,
close_fig,
):
validate_visualization_df(
petab.Problem(
condition_df=petab.get_condition_df(condition_file_Isensee),
visualization_df=petab.get_visualization_df(vis_spec_file_Isensee),
assert (
validate_visualization_df(
petab.Problem(
condition_df=petab.get_condition_df(condition_file_Isensee),
visualization_df=petab.get_visualization_df(
vis_spec_file_Isensee
),
)
)
is False
)
plot_with_vis_spec(
vis_spec_file_Isensee,
Expand Down Expand Up @@ -577,3 +582,21 @@ def test_validate(vis_file, request):
assert False is validate_visualization_df(
petab.Problem(visualization_df=petab.get_visualization_df(vis_file))
)


def test_validate_visualization_missing_dataset(
condition_file_Isensee,
data_file_Isensee,
vis_spec_file_Isensee,
simulation_file_Isensee,
):
petab_problem = petab.Problem(
condition_df=petab.get_condition_df(condition_file_Isensee),
measurement_df=petab.get_measurement_df(data_file_Isensee),
visualization_df=petab.get_visualization_df(vis_spec_file_Isensee),
)

assert validate_visualization_df(petab_problem) is False

petab_problem.visualization_df.loc[0, petab.DATASET_ID] = "missing_dataset"
assert validate_visualization_df(petab_problem) is True
Loading