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 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 51fd08d5d..4d4d119b3 100644 --- a/src/estimagic/utilities.py +++ b/src/estimagic/utilities.py @@ -1,3 +1,4 @@ +import difflib import warnings from hashlib import sha1 @@ -8,7 +9,6 @@ with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) - from fuzzywuzzy import process as fw_process def chol_params_to_lower_triangular_matrix(params): @@ -123,16 +123,17 @@ 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 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