-
Notifications
You must be signed in to change notification settings - Fork 51
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
Clean up the iloc in the tests #254
Changes from all commits
f1a8ae2
afc54b8
c623b14
3fd1005
7609dc2
50bf8aa
e049ccb
e4c0a4d
6839b8b
91a3928
0d81a47
1afd2b9
1ab2c67
7d4cb67
75c0972
45c9e0a
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 | ||||
---|---|---|---|---|---|---|
|
@@ -124,7 +124,7 @@ def test_u_nk_with_total_energy(): | |||||
|
||||||
# Check one specific value in the dataframe | ||||||
assert_almost_equal( | ||||||
extract_u_nk(dataset['data']['AllStates'][0], T=300).iloc[0][0], | ||||||
extract_u_nk(dataset['data']['AllStates'][0], T=300).loc[0][(0.0,0.0)].values[0], | ||||||
-11211.577658852531, | ||||||
decimal=6 | ||||||
) | ||||||
|
@@ -142,7 +142,7 @@ def test_u_nk_with_potential_energy(): | |||||
|
||||||
# Check one specific value in the dataframe | ||||||
assert_almost_equal( | ||||||
extract_u_nk(dataset['data']['AllStates'][0], T=300).iloc[0][0], | ||||||
extract_u_nk(dataset['data']['AllStates'][0], T=300).loc[0][(0.0,0.0)].values[0], | ||||||
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. see above |
||||||
-15656.557252200757, | ||||||
decimal=6 | ||||||
) | ||||||
|
@@ -161,7 +161,7 @@ def test_u_nk_without_energy(): | |||||
|
||||||
# Check one specific value in the dataframe | ||||||
assert_almost_equal( | ||||||
extract_u_nk(dataset['data']['AllStates'][0], T=300).iloc[0][0], | ||||||
extract_u_nk(dataset['data']['AllStates'][0], T=300).loc[0][(0.0,0.0)].values[0], | ||||||
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. see above |
||||||
0.0, | ||||||
decimal=6 | ||||||
) | ||||||
|
@@ -180,8 +180,9 @@ def _diag_sum(dataset): | |||||
u_nk = extract_u_nk(filename, T=300) | ||||||
|
||||||
# Calculate the sum of diagonal elements: | ||||||
for i in range(len(dataset['data'][leg])): | ||||||
ds += u_nk.iloc[i][i] | ||||||
for i, lambda_ in enumerate(u_nk.columns): | ||||||
#18.6 is the time step | ||||||
ds += u_nk.loc[i*186/10][lambda_].values[0] | ||||||
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. If this is a proper
Suggested change
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. This is not a proper 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. Ok, after looking at the data I see that this is a multiindex. But in this case wouldn't be
be cleaner? (I have no idea how to get something like ".loc[lambda_, (0.0, 0.0)]" instead of the values[0] but I find pandas indexing confusing...) 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. Yes, but we cannot get lambda_ beforehand and the lambda_ could be (0.0, 0.0) or (0.0, 0.0, 0.0), which is why for some of them, I could only do |
||||||
|
||||||
return ds | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -139,6 +139,8 @@ def compare_delta_f(self, X_delta_f): | |||||
assert X_delta_f[2] == pytest.approx(d_delta_f, rel=1e-3) | ||||||
|
||||||
def get_delta_f(self, est): | ||||||
# Use .iloc[0, -1] as we want to cater for both | ||||||
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. thanks for the comment |
||||||
# delta_f_.loc[0.0, 1.0] and delta_f_.loc[(0.0, 0.0), (0.0, 1.0)] | ||||||
return est.delta_f_.iloc[0, -1], est.d_delta_f_.iloc[0, -1] | ||||||
|
||||||
|
||||||
|
@@ -181,7 +183,7 @@ def test_failback_adaptive(self, n_uk_list): | |||||
# The hybr will fail on this while adaptive will work | ||||||
mbar = AutoMBAR().fit(alchemlyb.concat([n_uk[:2] for n_uk in | ||||||
n_uk_list])) | ||||||
assert np.isclose(mbar.d_delta_f_.iloc[0, -1], 1.76832, 0.1) | ||||||
assert np.isclose(mbar.d_delta_f_[(0.0, 0.0, 0.0)][(1.0, 1.0, 1.0)], 1.76832, 0.1) | ||||||
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. Can we write this as
Suggested change
|
||||||
|
||||||
def test_AutoMBAR_BGFS(): | ||||||
# A case where only BFGS would work | ||||||
|
@@ -227,6 +229,8 @@ def get_delta_f(self, est): | |||||
|
||||||
for i in range(len(est.d_delta_f_) - 1): | ||||||
ee += est.d_delta_f_.values[i][i+1]**2 | ||||||
# Use .iloc[0, -1] as we want to cater for both | ||||||
# delta_f_.loc[0.0, 1.0] and delta_f_.loc[(0.0, 0.0), (0.0, 1.0)] | ||||||
return est.delta_f_.iloc[0, -1], ee**0.5 | ||||||
|
||||||
class Test_Units(): | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,7 +60,7 @@ def dhdl(): | |||||
|
||||||
def test_kt2kt_number(self, dhdl): | ||||||
new_dhdl = to_kT(dhdl) | ||||||
assert 12.9 == pytest.approx(new_dhdl.iloc[0, 0], 0.1) | ||||||
assert 12.9 == pytest.approx(new_dhdl.loc[(0.0,0.0)], 0.1) | ||||||
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. pep8 space after comma
Suggested change
|
||||||
|
||||||
def test_kt2kt_unit(self, dhdl): | ||||||
new_dhdl = to_kT(dhdl) | ||||||
|
@@ -74,7 +74,7 @@ def test_kj2kt_unit(self, dhdl): | |||||
def test_kj2kt_number(self, dhdl): | ||||||
dhdl.attrs['energy_unit'] = 'kJ/mol' | ||||||
new_dhdl = to_kT(dhdl) | ||||||
assert 5.0 == pytest.approx(new_dhdl.iloc[0, 0], 0.1) | ||||||
assert 5.0 == pytest.approx(new_dhdl.loc[(0.0,0.0)], 0.1) | ||||||
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. pep8 space after comma |
||||||
|
||||||
def test_kcal2kt_unit(self, dhdl): | ||||||
dhdl.attrs['energy_unit'] = 'kcal/mol' | ||||||
|
@@ -84,7 +84,7 @@ def test_kcal2kt_unit(self, dhdl): | |||||
def test_kcal2kt_number(self, dhdl): | ||||||
dhdl.attrs['energy_unit'] = 'kcal/mol' | ||||||
new_dhdl = to_kT(dhdl) | ||||||
assert 21.0 == pytest.approx(new_dhdl.iloc[0, 0], 0.1) | ||||||
assert 21.0 == pytest.approx(new_dhdl.loc[(0.0,0.0)], 0.1) | ||||||
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. pep8 space after comma |
||||||
|
||||||
def test_unknown2kt(self, dhdl): | ||||||
dhdl.attrs['energy_unit'] = 'ddd' | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,13 +158,13 @@ def test_plot_convergence(): | |
slice = int(len(data_list[0])/num_points*i) | ||
u_nk_coul = alchemlyb.concat([data[:slice] for data in data_list]) | ||
estimate = MBAR().fit(u_nk_coul) | ||
forward.append(estimate.delta_f_.iloc[0,-1]) | ||
forward_error.append(estimate.d_delta_f_.iloc[0,-1]) | ||
forward.append(estimate.delta_f_.loc[0.0,1.0]) | ||
forward_error.append(estimate.d_delta_f_.loc[0.0,1.0]) | ||
Comment on lines
+161
to
+162
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. pep8 space after comma |
||
# Do the backward | ||
u_nk_coul = alchemlyb.concat([data[-slice:] for data in data_list]) | ||
estimate = MBAR().fit(u_nk_coul) | ||
backward.append(estimate.delta_f_.iloc[0,-1]) | ||
backward_error.append(estimate.d_delta_f_.iloc[0,-1]) | ||
backward.append(estimate.delta_f_.loc[0.0,1.0]) | ||
backward_error.append(estimate.d_delta_f_.loc[0.0,1.0]) | ||
Comment on lines
+166
to
+167
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. pep8 space after comma |
||
|
||
df = pd.DataFrame(data={'Forward': forward, | ||
'Forward_Error': forward_error, | ||
|
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.
PEP8 and using
.loc