-
Notifications
You must be signed in to change notification settings - Fork 667
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
Added exception and unittest for dist_mat_to_vec of analysis/psa.py (Part of #597) #1183
Changes from 2 commits
9a49244
ceb1618
1b04205
3af71be
bf8765b
cda6c57
dcc6168
cecc350
3943ddc
b706493
f12458e
ece534a
36acf58
376b0b1
bd94007
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -573,6 +573,10 @@ def dist_mat_to_vec(N, i, j): | |
:Returns: | ||
int, index (of the matrix element) in the corresponding distance vector | ||
""" | ||
try: | ||
validate_dist_mat_to_vec_inputs(N, i, j) | ||
except Exception as E: | ||
raise E | ||
if i > N or j > N: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to @sseyler comment, this test should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jbarnoud, but this doesn't include the case in which N > 2, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also the case where i or j is negative. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am only talking about replacing the line that says |
||
err_str = "Matrix indices are out of range; i and j must be less than" \ | ||
+ " N = {0:d}".format(N) | ||
|
@@ -591,6 +595,30 @@ def dist_mat_to_vec(N, i, j): | |
raise ValueError(err_str) | ||
|
||
|
||
def validate_dist_mat_to_vec_inputs(N, i, j): | ||
""" | ||
Validate the inputs of the function dist_mat_to_vec else raise an exception | ||
:param N: int | ||
:param i: int | ||
:param j: int | ||
:return: null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We follow numpy style docs in new code. You can have a look into other files for the look. |
||
""" | ||
|
||
# Validating if the inputs are integer | ||
try: | ||
NValue = int(N) | ||
iValue = int(i) | ||
jValue = int(j) | ||
except ValueError: | ||
raise ValueError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Integer evaluation isn't done like that. Here we just check if the input can be converted to an integer. So
Here you should also check if this still works with numpy integer types. |
||
|
||
# Check if the inputs are not out of bounds | ||
if N-1 > i > 0 and N >= 2 and i < j < N: | ||
pass | ||
else: | ||
raise ValueError | ||
|
||
|
||
class Path(object): | ||
"""Pre-process a :class:`MDAnalysis.Universe` object: (1) fit the | ||
trajectory to a reference structure, (2) convert fitted time series to a | ||
|
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 you don't want to catch the exception and to some special error handling with it then you don't need the try/except block. You can remove it here.