From afec5e270b8b2f8717b7b49fc2824b6475ead79a Mon Sep 17 00:00:00 2001 From: jac16 Date: Tue, 3 Sep 2024 11:26:55 -0400 Subject: [PATCH 1/4] Update pandas syntax to avoid FutureWarnings --- src/alchemlyb/estimators/bar_.py | 7 ++++--- src/alchemlyb/estimators/mbar_.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/alchemlyb/estimators/bar_.py b/src/alchemlyb/estimators/bar_.py index bb0afd4d..40373fa2 100644 --- a/src/alchemlyb/estimators/bar_.py +++ b/src/alchemlyb/estimators/bar_.py @@ -94,7 +94,7 @@ def fit(self, u_nk): # group u_nk by lambda states groups = u_nk.groupby(level=u_nk.index.names[1:]) N_k = [ - (len(groups.get_group(i)) if i in groups.groups else 0) + (len(groups.get_group((i,))) if i in groups.groups else 0) for i in u_nk.columns ] @@ -103,12 +103,13 @@ def fit(self, u_nk): d_deltas = np.array([]) for k in range(len(N_k) - 1): # get us from lambda step k - uk = groups.get_group(self._states_[k]) + uk = groups.get_group((self._states_[k],)) # get w_F w_f = uk.iloc[:, k + 1] - uk.iloc[:, k] # get us from lambda step k+1 - uk1 = groups.get_group(self._states_[k + 1]) + uk1 = groups.get_group((self._states_[k + 1],)) + # get w_R w_r = uk1.iloc[:, k] - uk1.iloc[:, k + 1] diff --git a/src/alchemlyb/estimators/mbar_.py b/src/alchemlyb/estimators/mbar_.py index e0ab594a..fb4d1ae3 100644 --- a/src/alchemlyb/estimators/mbar_.py +++ b/src/alchemlyb/estimators/mbar_.py @@ -122,7 +122,7 @@ def fit(self, u_nk): groups = u_nk.groupby(level=u_nk.index.names[1:]) N_k = [ - (len(groups.get_group(i)) if i in groups.groups else 0) + (len(groups.get_group((i,))) if i in groups.groups else 0) for i in u_nk.columns ] self._states_ = u_nk.columns.values.tolist() From 85d7504e48d482d4e6a965abdb4abde36c1677e1 Mon Sep 17 00:00:00 2001 From: jac16 Date: Thu, 19 Sep 2024 10:08:42 -0400 Subject: [PATCH 2/4] Bug fix --- src/alchemlyb/estimators/bar_.py | 18 +++++++++++++++--- src/alchemlyb/estimators/mbar_.py | 10 +++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/alchemlyb/estimators/bar_.py b/src/alchemlyb/estimators/bar_.py index 117b52fa..e0ce2647 100644 --- a/src/alchemlyb/estimators/bar_.py +++ b/src/alchemlyb/estimators/bar_.py @@ -97,7 +97,11 @@ def fit(self, u_nk): # group u_nk by lambda states groups = u_nk.groupby(level=u_nk.index.names[1:]) N_k = [ - (len(groups.get_group((i,))) if i in groups.groups else 0) + ( + len(groups.get_group(i if isinstance(i, tuple) else (i,))) + if i in groups.groups + else 0 + ) for i in u_nk.columns ] @@ -119,12 +123,20 @@ def fit(self, u_nk): continue # get us from lambda step k - uk = groups.get_group((self._states_[k],)) + uk = groups.get_group( + self._states_[k] + if isinstance(self._states_[k], tuple) + else (self._states_[k],) + ) # get w_F w_f = uk.iloc[:, k + 1] - uk.iloc[:, k] # get us from lambda step k+1 - uk1 = groups.get_group((self._states_[k + 1],)) + uk1 = groups.get_group( + self._states_[k + 1] + if isinstance(self._states_[k + 1], tuple) + else (self._states_[k + 1],) + ) # get w_R w_r = uk1.iloc[:, k] - uk1.iloc[:, k + 1] diff --git a/src/alchemlyb/estimators/mbar_.py b/src/alchemlyb/estimators/mbar_.py index 134c0431..45a648f6 100644 --- a/src/alchemlyb/estimators/mbar_.py +++ b/src/alchemlyb/estimators/mbar_.py @@ -81,9 +81,9 @@ class MBAR(BaseEstimator, _EstimatorMixOut): `n_bootstraps` option added. .. versionchanged:: 2.4.0 Handle initial estimate, initial_f_k, from bar in the instance - that not all lambda states represented as column headers are + that not all lambda states represented as column headers are represented in the indices of u_nk. - + """ def __init__( @@ -127,7 +127,11 @@ def fit(self, u_nk): groups = u_nk.groupby(level=u_nk.index.names[1:]) N_k = [ - (len(groups.get_group((i,))) if i in groups.groups else 0) + ( + len(groups.get_group(i if isinstance(i, tuple) else (i,))) + if i in groups.groups + else 0 + ) for i in u_nk.columns ] self._states_ = u_nk.columns.values.tolist() From f5a761072b2fbeda0d2398ab698bfc6baeda3a0f Mon Sep 17 00:00:00 2001 From: jac16 Date: Thu, 19 Sep 2024 10:19:01 -0400 Subject: [PATCH 3/4] Update CHANGES --- CHANGES | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 11e9e307..c384c632 100644 --- a/CHANGES +++ b/CHANGES @@ -20,9 +20,10 @@ The rules for this file: Enhancements - Addition of `block_average` function in both `convergence` and `visualization` (Issue #380, PR #381) - -Enhancements: - add CITATION.cff file with all authors from AUTHORS (issue #394, PR #395) + +Fixes + - Resolve pandas FutureWarnings in bar_.py and mbar_.py (issue #408 PR #407) 08/24/2024 xiki-tempula From 0b718ea4df82687379f8ea46c230dbbff337db6c Mon Sep 17 00:00:00 2001 From: Oliver Beckstein Date: Thu, 19 Sep 2024 09:33:48 -0700 Subject: [PATCH 4/4] Update CHANGES --- CHANGES | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 31d2aa67..11fe15a4 100644 --- a/CHANGES +++ b/CHANGES @@ -12,13 +12,14 @@ The rules for this file: * accompany each entry with github issue/PR number (Issue #xyz) * release numbers follow "Semantic Versioning" https://semver.org -09/19/2024 orbeckst +09/19/2024 orbeckst, jaclark5 * 2.4.1 Fixes - [doc] tutorial: use alchemlyb.concat (PR #399) - + - Resolve pandas FutureWarnings in bar_.py and mbar_.py (issue #408 PR #407) + 09/17/2024 jaclark5, orbeckst @@ -29,12 +30,10 @@ Enhancements `visualization` (Issue #380, PR #381) - add CITATION.cff file with all authors from AUTHORS (issue #394, PR #395) -Fixes - - Resolve pandas FutureWarnings in bar_.py and mbar_.py (issue #408 PR #407) - Changes - modernize build system: replaced setup.py,cfg with pyproject.toml (#385) + 08/24/2024 xiki-tempula * 2.3.2