Skip to content

Commit

Permalink
Replace fuzzywuzzy (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidatak97 authored Feb 17, 2023
1 parent 9acf723 commit a5bab0c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion .envs/testenv-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .envs/testenv-others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"cloudpickle",
"cyipopt",
"fides",
"fuzzywuzzy",
"joblib",
"nlopt",
"pandas",
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ install_requires =
bokeh<=2.4.3
click
cloudpickle
fuzzywuzzy
joblib
numba
numpy>=1.17.0
Expand Down
11 changes: 6 additions & 5 deletions src/estimagic/utilities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import difflib
import warnings
from hashlib import sha1

Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
hash_array,
isscalar,
number_of_triangular_elements_to_dimension,
propose_alternatives,
read_pickle,
robust_cholesky,
robust_inverse,
Expand Down Expand Up @@ -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

0 comments on commit a5bab0c

Please sign in to comment.