Skip to content

Commit f34ef8f

Browse files
committed
Handle empty variant_query results gracefully instead of raising ValueError
When variant_query filters leave zero SNPs in snp_allele_frequencies_advanced() and aa_allele_frequencies_advanced(), the code previously raised ValueError. This is a pre-existing fragility exposed by the region slicing fix (is not None checks can yield more accurate but smaller variant sets). Changed both sites to emit a UserWarning and continue, returning an empty but well-formed xr.Dataset with stable schema. This follows the existing precedent in aa_allele_frequencies() (line 354) which already handles empty results gracefully.
1 parent c594023 commit f34ef8f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

malariagen_data/anoph/snp_frq.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,10 @@ def snp_allele_frequencies_advanced(
671671

672672
# Check for no SNPs remaining after applying variant query.
673673
if np.count_nonzero(loc_variants) == 0:
674-
raise ValueError(
675-
f"No SNPs remaining after applying variant query {variant_query!r}."
674+
warnings.warn(
675+
f"No SNPs remaining after applying variant query {variant_query!r}. "
676+
"Returning dataset with zero variants.",
677+
stacklevel=2,
676678
)
677679

678680
# Convert boolean mask to integer indices for NumPy 2.x compatibility
@@ -813,8 +815,10 @@ def aa_allele_frequencies_advanced(
813815

814816
# Check for no SNPs remaining after applying variant query.
815817
if np.count_nonzero(loc_variants) == 0:
816-
raise ValueError(
817-
f"No SNPs remaining after applying variant query {variant_query!r}."
818+
warnings.warn(
819+
f"No SNPs remaining after applying variant query {variant_query!r}. "
820+
"Returning dataset with zero variants.",
821+
stacklevel=2,
818822
)
819823

820824
# Convert boolean mask to integer indices for NumPy 2.x compatibility

0 commit comments

Comments
 (0)