Skip to content

Commit b99c708

Browse files
timothymillarmergify[bot]
authored andcommitted
Raise ValueError for unknown method in pedigree_kinship
1 parent f89c78a commit b99c708

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sgkit/stats/pedigree.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ def pedigree_kinship(
567567
568568
Raises
569569
------
570+
ValueError
571+
If an unknown method is specified.
570572
ValueError
571573
If the pedigree contains a directed loop.
572574
ValueError
@@ -613,7 +615,8 @@ def pedigree_kinship(
613615
"Computation of the inverse additive relationship matrix for autopolyploid
614616
and multiple-ploidy populations." Theoretical and Applied Genetics 131: 851-860.
615617
"""
616-
assert method in {"diploid", "Hamilton-Kerr"}
618+
if method not in {"diploid", "Hamilton-Kerr"}:
619+
raise ValueError("Unknown method '{}'".format(method))
617620
ds = define_variable_if_absent(ds, variables.parent, parent, parent_indices)
618621
variables.validate(ds, {parent: variables.parent_spec})
619622
parent = da.asarray(ds[parent].data, chunks=ds[parent].shape)

sgkit/tests/test_pedigree.py

+13
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,16 @@ def test_pedigree_kinship__raise_on_parents_dimension(method):
486486
ValueError, match="Parent matrix must have shape \(samples, 2\)" # noqa: W605
487487
):
488488
pedigree_kinship(ds, method=method).compute()
489+
490+
491+
def test_pedigree_kinship__raise_on_invalid_method():
492+
ds = sg.simulate_genotype_call_dataset(n_variant=1, n_sample=5)
493+
ds["parent_id"] = ["samples", "parents"], [
494+
[".", "."],
495+
[".", "."],
496+
["S0", "S1"],
497+
["S1", "."],
498+
["S2", "S3"],
499+
]
500+
with pytest.raises(ValueError, match="Unknown method 'unknown'"):
501+
pedigree_kinship(ds, method="unknown")

0 commit comments

Comments
 (0)