Repository navigation
removed strings in minimizer indexing mechanism #347 - #348
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-3.0 #348 +/- ##
===============================================
- Coverage 92.71% 92.67% -0.05%
===============================================
Files 47 47
Lines 3406 3372 -34
===============================================
- Hits 3158 3125 -33
+ Misses 248 247 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
| fitter.switch_minimizer('Bumps') | ||
| from easyscience import AvailableMinimizers | ||
|
|
||
| fitter.switch_minimizer(AvailableMinimizers.Bumps) |
There was a problem hiding this comment.
Defaulting the minimizer allows me to remove create entirely.
damskii9992
left a comment
There was a problem hiding this comment.
Just some small comments
There was a problem hiding this comment.
Should this file not be renamed to minimizers.py and be moved into the minimizers folder?
| def test_available_minimizers(): | ||
| assert AvailableMinimizers.LMFit | ||
| assert AvailableMinimizers.LMFit_leastsq | ||
| assert AvailableMinimizers.LMFit_powell | ||
| assert AvailableMinimizers.LMFit_cobyla | ||
| assert AvailableMinimizers.LMFit_differential_evolution | ||
| assert AvailableMinimizers.LMFit_scipy_least_squares | ||
| assert AvailableMinimizers.Bumps | ||
| assert AvailableMinimizers.Bumps_simplex | ||
| assert AvailableMinimizers.Bumps_newton | ||
| assert AvailableMinimizers.Bumps_lm | ||
| assert AvailableMinimizers.DFO | ||
| assert AvailableMinimizers.DFO_leastsq | ||
| assert len(AvailableMinimizers) == 12 | ||
| assert Minimizers.LMFit | ||
| assert Minimizers.LMFit_leastsq | ||
| assert Minimizers.LMFit_powell | ||
| assert Minimizers.LMFit_cobyla | ||
| assert Minimizers.LMFit_differential_evolution | ||
| assert Minimizers.LMFit_scipy_least_squares | ||
| assert Minimizers.Bumps | ||
| assert Minimizers.Bumps_simplex | ||
| assert Minimizers.Bumps_newton | ||
| assert Minimizers.Bumps_lm | ||
| assert Minimizers.DFO | ||
| assert Minimizers.DFO_leastsq | ||
| assert len(Minimizers) == 12 |
There was a problem hiding this comment.
This test seems very redundant to me . . .
| def test_switch_minimizer_rejects_string(self, fitter: Fitter): | ||
| # When | ||
| mock_minimizer = MagicMock() | ||
| fitter._minimizer = mock_minimizer | ||
| mock_string_to_enum = MagicMock(return_value=10) | ||
| monkeypatch.setattr(easyscience.fitting.fitter, 'from_string_to_enum', mock_string_to_enum) | ||
|
|
||
| # Then | ||
| fitter.switch_minimizer('great-minimizer') | ||
| fitter._update_minimizer = MagicMock() | ||
|
|
||
| # Expect | ||
| fitter._update_minimizer.count(2) | ||
| mock_string_to_enum.assert_called_once_with('great-minimizer') | ||
| # Then Expect | ||
| with pytest.raises(TypeError, match='Minimizers'): | ||
| fitter.switch_minimizer('Bumps') | ||
| fitter._update_minimizer.assert_not_called() |
There was a problem hiding this comment.
Here's another test for removed functionality.
There was a problem hiding this comment.
Nope. This isn;t about removed string support.
The new isinstance check added in the PR adds to switch_minimizer.
The TypeError branch in the code has no test otherwise.
I think that the check is worth retaining. Without it, a caller who passes anything but a Minimizers type, gets AttributeError: object has no attribute 'package' from deep inside the code, instead of a message telling them to use Minimizers[name].
| Minimizers.Bumps_newton, | ||
| Minimizers.Bumps_lm, | ||
| Minimizers.DFO, | ||
| Minimizers.DFO_leastsq, |
There was a problem hiding this comment.
This test also seems a bit redundant, no?
There was a problem hiding this comment.
This test also seems a bit redundant, no?
The test copies the full enum into a list, so it breaks if a member is added or an engine is missing.
The property is public, though, so I'd keep a simple one-line test instead.
assert fitter.available_minimizers == list(Minimizers)
damskii9992
left a comment
There was a problem hiding this comment.
Lets get this sucker merged.
The
Fitter.switch_minimizermethod now only acceptsAvailableMinimizersenum members, raising aTypeErrorif a string or invalid type is provided. The oldcreatemethod and thefrom_string_to_enumconversion function are removedThe
available_minimizersproperty now returns a list of enum members instead of strings.