-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding B1 balance index and tests #2281
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2281 +/- ##
=======================================
Coverage 93.29% 93.30%
=======================================
Files 27 27
Lines 26089 26097 +8
Branches 1172 1175 +3
=======================================
+ Hits 24341 24349 +8
Misses 1718 1718
Partials 30 30
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Looks great! I don't understand why we're rounding though? |
It's because of the tests, having something like this didn't look clean (and I felt it could lead to errors): def test_b1(self):
assert self.tree().b1_index() == 1.8333333333333333 And I wasn't sure this was clean either, since it's not testing the output of the method itself: def test_b1(self):
assert round(self.tree().b1_index(),3) == 1.833 But I guess there is a clean general way of working around tests in that case? |
5089530
to
5aa6337
Compare
By the way: I wrote in the doc that the output is a |
Ah, I see. I think the usual way to handle this would be something like
Good point. The cleanest way to fix this would be to set |
By removing the rounding I get now this kind of errors: assert tree.b1_index() == b1_index_definition(tree)
E assert 19.4718253968254 == 19.471825396825395 I guess I should use |
Use
|
I put Is it an issue if the definition method output is not always a float, or should I force it to float too? The tests do pass without it. |
Do the tests not pass at the default tolerance? I would have expected the values to be very close.
that's fine, it doesn't really matter. |
For this test the default relative tolerance is indeed working, as the difference is very small: assert tree.b1_index() == pytest.approx(b1_index_definition(tree)) But for this one, the default 1e-6 relative tolerance is too small compared to the difference between 1.833333.. and 1.833: assert self.tree().b1_index() == pytest.approx(1.833) So I had two solutions that pass the test: assert self.tree().b1_index() == pytest.approx(1.833, rel=1e-3) or assert self.tree().b1_index() == pytest.approx(1.8333333) The first one seemed cleaner to me. |
Ah, I see. When you're comparing with a fixed value either way is good. Whatever you prefer. |
5aa6337
to
9db822c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, spotted one issue in docstring
python/tskit/trees.py
Outdated
.. seealso:: See `Shao and Sokal (1990) | ||
<https://www.jstor.org/stable/2992186>`_ for details. | ||
|
||
:return: The B1 balance index (rounded). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete (rounded)
9db822c
to
72474ec
Compare
Here is the PR for B1 balance index. Compared to #2251 I just added a
round
function at the end. @jeromekelleher