From 156e9f6eb5932daddc926c8b6f0afda872fabacb Mon Sep 17 00:00:00 2001 From: Aida Takhmazova Date: Mon, 13 Feb 2023 22:48:55 +0100 Subject: [PATCH 1/5] Replace fuzzywuzzy with difflib in propose_alternative(). --- src/estimagic/utilities.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/estimagic/utilities.py b/src/estimagic/utilities.py index 51fd08d5d..8134d780d 100644 --- a/src/estimagic/utilities.py +++ b/src/estimagic/utilities.py @@ -1,5 +1,6 @@ import warnings from hashlib import sha1 +import difflib import cloudpickle import numpy as np @@ -123,16 +124,15 @@ def propose_alternatives(requested, possibilities, number=3): Example: >>> possibilities = ["scipy_lbfgsb", "scipy_slsqp", "nlopt_lbfgsb"] >>> propose_alternatives("scipy_L-BFGS-B", possibilities, number=1) - ['scipy_lbfgsb'] + ['scipy_slsqp'] >>> propose_alternatives("L-BFGS-B", possibilities, number=2) - ['scipy_lbfgsb', 'nlopt_lbfgsb'] + ['scipy_slsqp', 'scipy_lbfgsb'] """ number = min(number, len(possibilities)) with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) - proposals_w_probs = fw_process.extract(requested, possibilities, limit=number) - proposals = [proposal[0] for proposal in proposals_w_probs] + proposals = difflib.get_close_matches(requested, possibilities, n=number, cutoff=0) return proposals From 5c94a63b6682c357209f007eea401a8014c7fe31 Mon Sep 17 00:00:00 2001 From: aidatak97 Date: Tue, 14 Feb 2023 01:18:41 +0300 Subject: [PATCH 2/5] Rewrite the propose_alternatives function using difflib. --- src/estimagic/utilities.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/estimagic/utilities.py b/src/estimagic/utilities.py index 51fd08d5d..a26ecfbf9 100644 --- a/src/estimagic/utilities.py +++ b/src/estimagic/utilities.py @@ -5,6 +5,7 @@ import numpy as np import pandas as pd from scipy.linalg import ldl, qr +import difflib with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) @@ -123,16 +124,15 @@ def propose_alternatives(requested, possibilities, number=3): Example: >>> possibilities = ["scipy_lbfgsb", "scipy_slsqp", "nlopt_lbfgsb"] >>> propose_alternatives("scipy_L-BFGS-B", possibilities, number=1) - ['scipy_lbfgsb'] + ['scipy_slsqp'] >>> propose_alternatives("L-BFGS-B", possibilities, number=2) - ['scipy_lbfgsb', 'nlopt_lbfgsb'] + ['scipy_slsqp', 'scipy_lbfgsb'] """ number = min(number, len(possibilities)) with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) - proposals_w_probs = fw_process.extract(requested, possibilities, limit=number) - proposals = [proposal[0] for proposal in proposals_w_probs] + proposals = proposals = difflib.get_close_matches(requested, possibilities, n=number, cutoff=0) return proposals From 0b4ac4eb452486768b3099bc53de00fb7364faa6 Mon Sep 17 00:00:00 2001 From: Aida Takhmazova Date: Tue, 14 Feb 2023 19:11:27 +0100 Subject: [PATCH 3/5] Add tests for propose_alternatives function. --- tests/test_utilities.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 55ca9491d..12492ae22 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -14,6 +14,7 @@ hash_array, isscalar, number_of_triangular_elements_to_dimension, + propose_alternatives, read_pickle, robust_cholesky, robust_inverse, @@ -239,3 +240,11 @@ def test_get_rng_correct_input(seed): def test_get_rng_wrong_input(seed): with pytest.raises(TypeError): get_rng(seed) + + +def test_propose_alternatives(): + possibilities = ["scipy_lbfgsb", "scipy_slsqp", "nlopt_lbfgsb"] + inputs = [["scipy_L-BFGS-B", 1], ["L-BFGS-B", 2]] + expected = [["scipy_slsqp"], ["scipy_slsqp", "scipy_lbfgsb"]] + for inp, exp in zip(inputs, expected): + assert propose_alternatives(inp[0], possibilities, number=inp[1]) == exp From 579357c7bcba7d423c5f3309d7f6913b293f6dd2 Mon Sep 17 00:00:00 2001 From: Aida Takhmazova Date: Tue, 14 Feb 2023 19:26:31 +0100 Subject: [PATCH 4/5] Remove fuzzywuzzy dependencies. --- docs/source/conf.py | 1 - environment.yml | 1 - setup.cfg | 1 - src/estimagic/utilities.py | 8 ++++---- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index fb8f336a9..58abca26c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -66,7 +66,6 @@ "cloudpickle", "cyipopt", "fides", - "fuzzywuzzy", "joblib", "nlopt", "pandas", diff --git a/environment.yml b/environment.yml index 79e11d0ab..3b7b6e85a 100644 --- a/environment.yml +++ b/environment.yml @@ -21,7 +21,6 @@ dependencies: - bokeh<=2.4.3 # run, tests - click # run, tests - cloudpickle # run, tests - - fuzzywuzzy # run, tests - joblib # run, tests - numba # run, tests - numpy>=1.17.0 # run, tests diff --git a/setup.cfg b/setup.cfg index 4ce11f68e..ab268cd59 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,7 +38,6 @@ install_requires = bokeh<=2.4.3 click cloudpickle - fuzzywuzzy joblib numba numpy>=1.17.0 diff --git a/src/estimagic/utilities.py b/src/estimagic/utilities.py index fedeb7410..4d4d119b3 100644 --- a/src/estimagic/utilities.py +++ b/src/estimagic/utilities.py @@ -1,16 +1,14 @@ +import difflib import warnings from hashlib import sha1 -import difflib import cloudpickle import numpy as np import pandas as pd from scipy.linalg import ldl, qr -import difflib with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) - from fuzzywuzzy import process as fw_process def chol_params_to_lower_triangular_matrix(params): @@ -133,7 +131,9 @@ def propose_alternatives(requested, possibilities, number=3): number = min(number, len(possibilities)) with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) - proposals = difflib.get_close_matches(requested, possibilities, n=number, cutoff=0) + proposals = difflib.get_close_matches( + requested, possibilities, n=number, cutoff=0 + ) return proposals From d4df55b297ba5a3939b64cc0918432fca73cc864 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Feb 2023 18:31:33 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .envs/testenv-linux.yml | 1 - .envs/testenv-others.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.envs/testenv-linux.yml b/.envs/testenv-linux.yml index 12d83b468..0535fecb6 100644 --- a/.envs/testenv-linux.yml +++ b/.envs/testenv-linux.yml @@ -15,7 +15,6 @@ dependencies: - bokeh<=2.4.3 # run, tests - click # run, tests - cloudpickle # run, tests - - fuzzywuzzy # run, tests - joblib # run, tests - numba # run, tests - numpy>=1.17.0 # run, tests diff --git a/.envs/testenv-others.yml b/.envs/testenv-others.yml index d35153d2e..475f786c2 100644 --- a/.envs/testenv-others.yml +++ b/.envs/testenv-others.yml @@ -14,7 +14,6 @@ dependencies: - bokeh<=2.4.3 # run, tests - click # run, tests - cloudpickle # run, tests - - fuzzywuzzy # run, tests - joblib # run, tests - numba # run, tests - numpy>=1.17.0 # run, tests