Skip to content

Commit d450650

Browse files
authored
Merge pull request #1144 from suhr25/fix/cohorts-dict-eval-error-handling
fix: improve error handling for invalid pandas queries in _locate_cohorts()
2 parents 84d190d + fd23821 commit d450650

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

malariagen_data/anoph/sample_metadata.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,12 @@ def _locate_cohorts(*, cohorts, data, min_cohort_size):
18391839
# to pandas queries.
18401840

18411841
for coh, query in cohorts.items():
1842-
loc_coh = data.eval(query).values
1842+
try:
1843+
loc_coh = data.eval(query).values
1844+
except Exception as e:
1845+
raise ValueError(
1846+
f"Invalid query for cohort {coh!r}: {query!r}. Error: {e}"
1847+
) from e
18431848
coh_dict[coh] = loc_coh
18441849

18451850
else:

0 commit comments

Comments
 (0)