optimagic-dev / optimagic

optimagic is a Python package for numerical optimization. It is a unified interface to optimizers from SciPy, NlOpt and other packages. optimagic's minimize function works just like SciPy's, so you don't have to adjust your code. You simply get more optimizers for free. On top you get diagnostic tools, parallel numerical derivatives and more.
https://optimagic.readthedocs.io/
MIT License
270 stars 30 forks source link

Optimize code to replace the df #452

Closed Kaniyaki closed 4 months ago

codecov[bot] commented 1 year ago

Codecov Report

Attention: Patch coverage is 82.35294% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/estimagic/parameters/check_constraints.py 73.91% 6 Missing :warning:
Files with missing lines Coverage Δ
tests/parameters/test_check_constraints.py 100.00% <100.00%> (ø)
src/estimagic/parameters/check_constraints.py 87.39% <73.91%> (-0.57%) :arrow_down:
Kaniyaki commented 1 year ago

Optimized the "check_fixes_and_bounds" function, which originally had a runtime of 5.61 ms. The main problem was that it used DataFrame. Instead of it, I used a dictionary and added the "_iloc" function as a substitute for DataFrame.iloc. Current runtime is 55 µs, which is a significant improvement. In the end, I made sure that all tests passed, and they did. Below, you can see the comparison for the runtime using %timeit and %lprun. lprun_comparison.pdf timeit_comparison.pdf