-
Notifications
You must be signed in to change notification settings - Fork 648
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
Issue 1006: minor fixes and several new unit tests for PSA module #1508
Issue 1006: minor fixes and several new unit tests for PSA module #1508
Conversation
I just checked that the changes I made to the return statements in
... and it appears that it doesn't: ======================================================================
ERROR: Test whether actual distances between frames of Hausdorff
----------------------------------------------------------------------
Traceback (most recent call last):
File "/nfs/homes3/sseyler/Repositories/python/mdanalysis/testsuite/MDAnalysisTests/analysis/test_psa.py", line 157, in test_distances_from_hausdorff_pairs_frames
p, q = self.hausd_pairs[pairidx]['frames']
TypeError: list indices must be integers, not float I will look more closely next chance I get to see if what the problem is (or if the problem is me). |
@sseyler it might be the division causing floats? |
@sseyler you can enforce the old style in division using double backslashes |
Yep, that was the problem. Using double backslashes now. |
Btw, you should rebase against the latest develop: there is no nose test anymore #884 . Make sure that this works with the latest and greatest. |
@sseyler this is failing because of the linter. Add |
…_wavg_weight() and test_asymmetric_avg_weight(); need diff names for each test.
…est names: test_asymmetric_weight()
…now also gives distance matrix
…lysis docs for dist matrix D
- Added future division and six.range to test_psa.py - Separated pairs analysis (_run_pairs_analysis) from _run; moved plotting before - Adding a couple distance matrix checks to PSAnalysis methods - PSAnalysis.cluster now uses generated distance matrix D by default and checks for proper dist matrix format if dist_mat kwarg is specified - updated docstring for PSAnalysis.cluster
e98f242
to
7a5b9a7
Compare
package/MDAnalysis/analysis/psa.py
Outdated
@@ -254,6 +254,10 @@ def get_path_metric_func(name): | |||
except KeyError as key: | |||
print("Path metric {0} not found. Valid selections: ".format(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.
Shouldn't this raise a KeyError?
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.
Maybe change it to a value error. But I would keep the exception. An invalid selection does sound like a grave mistake
package/MDAnalysis/analysis/psa.py
Outdated
filename = kwargs.pop('filename', str(metric)) | ||
self.save_result(filename=filename) | ||
filename = kwargs.pop('filename', metric) | ||
if type(metric) is str: |
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.
if isinstance(metrix, six.string_types)
Please no print(). Use logger and warning or possibly just raise the damn exception and let the user do things properly. Failing is a good thing.
In package/MDAnalysis/analysis/psa.py <#1508 (comment)>:
> @@ -254,6 +254,10 @@ def get_path_metric_func(name):
except KeyError as key:
print("Path metric {0} not found. Valid selections: ".format(key))
Oliver Beckstein
orbeckst@gmail.com * orbeckst@gmx.net
|
ping @sseyler |
… test now checks KeyError is raised
@@ -171,17 +171,13 @@ class TestPSAExceptions(TestCase): | |||
def test_get_path_metric_func_bad_key(self): | |||
'''Test that KeyError is caught by | |||
get_path_metric_func().''' | |||
|
|||
try: | |||
with self.assertRaises(KeyError): |
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.
with pytest.raises(KeyError):
PSA.get_path_metric_func('foobar')
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.
Yeah, I put my changes on hold since, once I rebased properly, realized everything is now pytest-specific. Hoping to finish this PR within the week.
package/MDAnalysis/analysis/psa.py
Outdated
# raise KeyError(err_str) | ||
err_str = "Path metric {0} not found. Valid selections: ".format(key) | ||
err_str += " ".join(["\"{0}\"".format(name) for name in path_metrics.keys()]) | ||
raise KeyError(err_str) |
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.
You can use multiline strings
raise KeyError("Path metric {} not found. Valid Selections: {}".format(
key, ' '.join(['"{}"'.format(name) for name in path_metrics.keys()]))
Ping Dr @sseyler , can you finish this up? |
@sseyler said #1508 (comment):
... on Aug 2. Time to finish it up before the year is over. We should have the fixes for #1507 in 0.17.0 if possible (and the sooner we have higher test coverage the better!) |
Ok cool, this should be good to go. Make this a merge commit so that authorship isn't messed with |
@richardjgowers Forgot to say this earlier: Thanks, Richard! I was gonna have to do this over the holidays otherwise. I owe you a beer next time we meet! |
Addresses Issue #1006 (increase code coverage in PSA) and related Issue #1507 (Some PSA module components don't behave as expected). Brings PSA code coverage up to 73% according to report from
mda_nosetests
:gives:
Changes made in this Pull Request:
MDAnalysis.analysis.psa.dist_mat_to_vec()
now returnsint
type via explicit casting of return statements (Some PSA module components don't behave as expected #1507).run_pairs_analysis()
, now also gives the distance matrix, as with the simplerrun()
method, by default (Some PSA module components don't behave as expected #1507).psa.run(metric=PSA.hausdorff)
versuspsa.run(metric='hausdorff')
as a kwarg and a filename isn't explicitly specified topsa.run()
.test_explicit_metric()
—check that an explicit Python function reference, as opposed to a string specifier, works as keyword argument, i.e.,psa.run(metric=psa.hausdorff)
versuspsa.run(metric='hausdorff')
test_hausdorff_pairs_distances()
—check that Hausdorff distances produced by Hausdorff pairs analysis frompsa.run_pairs_analysis(neighbors=True, hausdorff_pairs=True)
are equal to Hausdorff distances generated in the usual way withpsa.run()
test_distances_from_hausdorff_pairs_frames()
—check, for all pairs of paths, that the actual distance (computed manually by utilizingpsa.sqnorm()
) between two frames corresponding to a Hausdorff pair is equal to the Hausdorff distance between the two corresponding paths.PR Checklist