malariagen / malariagen-data-python

Analyse MalariaGEN data from Python
https://malariagen.github.io/malariagen-data-python/latest/
MIT License
13 stars 24 forks source link

Warning while running tests/anoph/test_fst.py for af1: RuntimeWarning: invalid value encountered in divide #598

Open jonbrenas opened 1 month ago

jonbrenas commented 1 month ago

While running tests/anoph/test_fst.py for af1, a RuntimeWarning is raised. This is due to the fact the denominator in the Hudson Fst (i.e., the divergence between the two cohorts) is 0 (i.e., the two cohorts are identical for the whole window). This is actually the correct behaviour so I am not sure what to do about this. My instinct would be to catch the Warning so that it stops showing and maybe raise another one informing the user that the divergence was 0 in at least some of the windows (because the Warning is actually raised by allel, the exact number of such windows isn't immediately available) and that it was chosen that the Fst would be 0 in these windows.

jonbrenas commented 1 month ago

That's the warning, for the record:

tests/anoph/test_fst.py::test_fst_gwss[af1_sim]
  /Users/jb52/Library/Caches/pypoetry/virtualenvs/malariagen-data-IrlFm8eo-py3.10/lib/python3.10/site-packages/allel/stats/fst.py:619: RuntimeWarning:

  invalid value encountered in divide
alimanfoo commented 3 weeks ago

Example of using np.errstate() to suppress warnings within a specific section of code ... https://github.com/malariagen/malariagen-data-python/blob/b4a3cc96c5339b3fc9937080e8da2fb2813b1fd0/malariagen_data/anoph/snp_frq.py#L522