Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion allel/stats/hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def heterozygosity_expected(af, ploidy, fill=np.nan):
out = 1 - np.sum(np.power(af, ploidy), axis=1)

# fill values where allele frequencies could not be calculated
af_sum = np.sum(af, axis=1)
precision = np.finfo(af.dtype).precision
af_sum = np.round(np.sum(af, axis=1), precision)
with ignore_invalid():
out[(af_sum < 1) | np.isnan(af_sum)] = fill

Expand Down
5 changes: 4 additions & 1 deletion allel/test/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,10 @@ def refimpl(f, ploidy, fill=0):
"""Limited reference implementation for testing purposes."""

# check allele frequencies sum to 1
af_sum = np.sum(f, axis=1)
# round to suitable precision for the dtype
af_sum = (np.sum(f, axis=1))
precision = np.finfo(af_sum.dtype).precision
af_sum = np.round(np.sum(f, axis=1), precision)

# assume three alleles
p = f[:, 0]
Expand Down