Skip to content

Commit 8450add

Browse files
authored
Merge branch 'master' into GH1162-always-return-figure
2 parents 2b3f9b5 + 61ae527 commit 8450add

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

malariagen_data/anoph/phenotypes.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ def _load_phenotype_data(
7070
df_pheno["sample_set"] = sample_set
7171
phenotype_dfs.append(df_pheno)
7272

73-
except Exception as e:
74-
warnings.warn(
75-
f"Unexpected error loading phenotype data for {sample_set}: {e}"
76-
)
73+
except (KeyError, FileNotFoundError, IOError) as e:
74+
warnings.warn(f"Error loading phenotype data for {sample_set}: {e}")
7775
continue
7876

7977
if not phenotype_dfs:
@@ -307,11 +305,6 @@ def _create_phenotype_dataset(
307305
except ValueError as e:
308306
warnings.warn(f"Value error in variant data merging: {e}")
309307
return ds
310-
except Exception as e:
311-
warnings.warn(
312-
f"Unexpected error selecting/merging variant data: {e}"
313-
)
314-
return ds
315308

316309
return ds
317310

@@ -346,11 +339,7 @@ def phenotype_data(
346339
return pd.DataFrame()
347340

348341
# 3. Get sample metadata for all samples that have phenotype data
349-
try:
350-
df_metadata = self.sample_metadata(sample_sets=sample_sets_norm)
351-
except Exception as e:
352-
warnings.warn(f"Error fetching sample metadata: {e}")
353-
return pd.DataFrame()
342+
df_metadata = self.sample_metadata(sample_sets=sample_sets_norm)
354343

355344
if df_metadata.empty:
356345
warnings.warn("No sample metadata found for samples with phenotype data")
@@ -373,8 +362,8 @@ def phenotype_data(
373362
df_merged = df_merged.query(
374363
sample_query, **(sample_query_options or {})
375364
)
376-
except Exception as e:
377-
warnings.warn(f"Error applying sample_query '{sample_query}': {e}")
365+
except (pd.errors.UndefinedVariableError, SyntaxError) as e:
366+
warnings.warn(f"Invalid sample_query '{sample_query}': {e}")
378367
return pd.DataFrame()
379368

380369
# 6. Apply cohort filtering
@@ -494,7 +483,7 @@ def phenotype_sample_sets(self) -> List[str]:
494483

495484
if self._fs.exists(phenotype_path):
496485
phenotype_sample_sets.append(sample_set)
497-
except Exception:
486+
except (KeyError, FileNotFoundError):
498487
continue
499488

500489
return phenotype_sample_sets

0 commit comments

Comments
 (0)