From 62290570fc937b1d26dff00b526b240df431812d Mon Sep 17 00:00:00 2001 From: Brioch Date: Wed, 12 Aug 2020 09:46:07 +1200 Subject: [PATCH] Fixing issues with duplicated indicies in pandas.index.intersection() Pandas 1.1 changes behaviour of index.intersection() to return duplicated indicies in the intersection. This causes issues in the application of mults as .loc[] methods propagate this duplication (doubling duplicates). adding .drop_duplicates() to the intersection fixes this. --- autotest/pst_from_tests.py | 12 ++++++------ pyemu/utils/helpers.py | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/autotest/pst_from_tests.py b/autotest/pst_from_tests.py index 320b62d90..170c48b4e 100644 --- a/autotest/pst_from_tests.py +++ b/autotest/pst_from_tests.py @@ -1301,9 +1301,9 @@ def mf6_freyberg_direct_test(): raise Exception("recharge too diff") if __name__ == "__main__": - #freyberg_test() - #freyberg_prior_build_test() - mf6_freyberg_test() - #mf6_freyberg_shortnames_test() - #mf6_freyberg_da_test() - #mf6_freyberg_direct_test() + freyberg_test() + # freyberg_prior_build_test() + # mf6_freyberg_test() + # mf6_freyberg_shortnames_test() + # mf6_freyberg_da_test() + # mf6_freyberg_direct_test() diff --git a/pyemu/utils/helpers.py b/pyemu/utils/helpers.py index 305192a3f..cdf640ed8 100644 --- a/pyemu/utils/helpers.py +++ b/pyemu/utils/helpers.py @@ -3512,7 +3512,8 @@ def apply_genericlist_pars(df): names=mlt.index_cols) if mlts.index.nlevels < 2: # just in case only one index col is used mlts.index = mlts.index.get_level_values(0) - common_idx = new_df.index.intersection(mlts.index).sort_values() + common_idx = new_df.index.intersection( + mlts.index).sort_values().drop_duplicates() mlt_cols = [str(col) for col in mlt.use_cols] new_df.loc[common_idx, mlt_cols] = (new_df.loc[common_idx, mlt_cols] * mlts.loc[common_idx, mlt_cols]