Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace fuzzywuzzy #437

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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