-
Notifications
You must be signed in to change notification settings - Fork 14
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
Updated functionality for add_rfree
and copy_rfree
#170
Conversation
Codecov Report
@@ Coverage Diff @@
## main #170 +/- ##
==========================================
- Coverage 98.41% 98.30% -0.11%
==========================================
Files 44 44
Lines 1704 1713 +9
==========================================
+ Hits 1677 1684 +7
- Misses 27 29 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Thanks for taking care of these -- your changes look good to me. My only updates:
- Please change
custom_rfree_key
-->rfree_key
. I would rather keep the function arguments as short as possible, and I don't think the "custom" adds clarification. - Please delete the now obsolete
unittest
code -- yourpytest
versions look good to me.
- renamed custom_rfree_key to custom_rfree_key - removed obsolete unittest code
tests/utils/test_rfree.py
Outdated
def test_copy_rfree_errors(data_fmodel): | ||
""" | ||
Test expected ValueErrors for rs.utils.copy_rfree | ||
""" | ||
with pytest.raises(ValueError): | ||
rs.utils.copy_rfree(data_fmodel, data_fmodel) | ||
|
||
return | ||
with pytest.raises(ValueError): | ||
rs.utils.copy_rfree(data_fmodel, data_fmodel, rfree_key="missing key") |
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.
I didn't catch this before, but this can be simplified to:
@pytest.mark.parametrize("rfree_key", [None, "missing key"])
def test_copy_rfree_errors(data_fmodel, rfree_key):
"""
Test expected ValueErrors for rs.utils.copy_rfree()
"""
with pytest.raises(ValueError):
rs.utils.copy_rfree(data_fmodel, data_fmodel, rfree_key=rfree_key)
I think the above is true... let me know if I'm mistaken
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.
Oo good call, I think you're right. Didn't occur to me because it's a different ValueError
, but yeah this should work.
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.
I'll just clarify in the docstring what the two ValueErrors are, because I think the condensed version is a little harder to parse
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.
In theory a slightly more rigorous test would be to confirm that the "missing key" case throws an error even when "R-free-flag" or "FreeR_flags" is present, but I think that's probably overkill.
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.
yep, I think your comment there is good.
I think the test you just mentioned is a pretty good one because it tests the intended implementation (that rfree_key
supercedes any other default column names). If we change the order of the if
clauses in the future, that could change, so I think those sorts of tests are useful for making sure as many corner cases are covered.
ValueError still referred to the argument as "custom_rfree_key" rather than "rfree_key"
for more information, see https://pre-commit.ci
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.
Looks good -- thanks for making the fixes!
Making changes to
rs.utils.add_rfree
as per #169 and changes tors.utils.copy_rfree
as per #159add_rfree
takesseed
The
seed
is passed through tonp.random.default_rng(seed)
, such that runningadd_rfree
again with the sameseed
results in the same flags.seed
defaults toNone
, and convenientlynp.random.default_rng(None)
is a valid call.A test was added to
test_add_rfree()
to confirm that flags are the same when a seed is used, and are different when a seed is not used.copy_rfree
handles column names flexiblyThe recent addition of the
ccp4_convention
parameter toadd_rfree
means that there are two possible names for an r-free column,"R-free-flags"
(phenix convention) or"FreeR_flag"
(ccp4 convention).copy_rfree
will now by default search the provideddataset_with_rfree
for a column named"R-free-flags"
, then"FreeR_flag"
, and throw aValueError
if neither is found.The user can override this behavior via the
custom_rfree_key
argument if the r-free flag column uses any other naming convention.A function
test_copy_rfree()
was added to test successfully copying in all combinations of column naming. A functiontest_copy_rfree_errors()
was added to verify thatValueError
s are thrown when appropriate.Old
unittest
codeThere is an existing test for
copy_rfree
written withunittest
. I believe that all key functionalities are tested in my newpytest
code, making theunittest
code redundant, but I left it in for now and labelled it in its docstring that it is a "legacy" version. Let me know if there's anything in theunittest
code that I should additionally migrate, and/or if theunittest
code should me removed altogether.