Skip to content

Commit 6d36546

Browse files
committed
Add check that optional taxon_by is not None in ..._frequencies_advanced funcs
1 parent 24c2fe6 commit 6d36546

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

malariagen_data/anoph/cnv_frq.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ def gene_cnv_frequencies_advanced(
447447
inline_array: base_params.inline_array = base_params.inline_array_default,
448448
taxon_by: Optional[frq_params.taxon_by] = frq_params.taxon_by_default,
449449
) -> xr.Dataset:
450+
# Check that the taxon_by default hasn't been subverted.
451+
# This avoids type-checking errors, e.g. with `getattr`.
452+
if taxon_by is None:
453+
raise ValueError("`taxon_by` cannot be set to `None`.")
454+
450455
regions: List[Region] = parse_multi_region(self, region)
451456
del region
452457

malariagen_data/anoph/hap_frq.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ def haplotypes_frequencies_advanced(
155155
inline_array: base_params.inline_array = base_params.inline_array_default,
156156
taxon_by: Optional[frq_params.taxon_by] = frq_params.taxon_by_default,
157157
) -> xr.Dataset:
158+
# Check that the taxon_by default hasn't been subverted.
159+
# This avoids type-checking errors, e.g. with `getattr`.
160+
if taxon_by is None:
161+
raise ValueError("`taxon_by` cannot be set to `None`.")
162+
158163
# Load sample metadata.
159164
df_samples = self.sample_metadata(
160165
sample_sets=sample_sets,

malariagen_data/anoph/snp_frq.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ def snp_allele_frequencies_advanced(
453453
inline_array: base_params.inline_array = base_params.inline_array_default,
454454
taxon_by: Optional[frq_params.taxon_by] = frq_params.taxon_by_default,
455455
) -> xr.Dataset:
456+
# Check that the taxon_by default hasn't been subverted.
457+
# This avoids type-checking errors, e.g. with `getattr`.
458+
if taxon_by is None:
459+
raise ValueError("`taxon_by` cannot be set to `None`.")
460+
456461
# Load sample metadata.
457462
df_samples = self.sample_metadata(
458463
sample_sets=sample_sets,
@@ -680,8 +685,13 @@ def aa_allele_frequencies_advanced(
680685
ci_method: Optional[frq_params.ci_method] = "wilson",
681686
chunks: base_params.chunks = base_params.native_chunks,
682687
inline_array: base_params.inline_array = base_params.inline_array_default,
683-
taxon_by: frq_params.taxon_by = frq_params.taxon_by_default,
688+
taxon_by: Optional[frq_params.taxon_by] = frq_params.taxon_by_default,
684689
) -> xr.Dataset:
690+
# Check that the taxon_by default hasn't been subverted.
691+
# This avoids type-checking errors, e.g. with `getattr`.
692+
if taxon_by is None:
693+
raise ValueError("`taxon_by` cannot be set to `None`.")
694+
685695
# Begin by computing SNP allele frequencies.
686696
ds_snp_frq = self.snp_allele_frequencies_advanced(
687697
transcript=transcript,

0 commit comments

Comments
 (0)