-
Notifications
You must be signed in to change notification settings - Fork 2
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
Migrate to Ruff #62
Merged
Merged
Migrate to Ruff #62
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #62 +/- ##
==========================================
- Coverage 91.38% 89.22% -2.16%
==========================================
Files 42 42
Lines 1729 1782 +53
==========================================
+ Hits 1580 1590 +10
- Misses 149 192 +43
|
marcofavoritobi
force-pushed
the
ruff
branch
20 times, most recently
from
August 30, 2023 15:31
31060a5
to
743d153
Compare
marcofavoritobi
force-pushed
the
ruff
branch
4 times, most recently
from
September 1, 2023 10:45
35ca6c5
to
0440035
Compare
To reproduce the errors: ``` ruff check --select "SLF" black_it tests examples scripts ``` Some errors were fixed automatically by using the flag --fix, while others manually (e.g. g.legend in place of g._legend in plot module).
To reproduce the errors: ``` ruff check --select "SIM" black_it tests examples scripts ``` All the errors were automatically fixed with --fix flag.
To reproduce the errors: ``` ruff check --select "TCH" black_it tests examples scripts ``` All the errors were fixed by using the --fix flag.
To reproduce the errors: ``` ruff check --select "ARG" black_it tests examples scripts ``` Errors were mostly fixed manually.
To reproduce the errors: ``` ruff check --select "PTH" black_it tests examples scripts ``` Errors were mostly fixed manually.
To reproduce the errors: ``` ruff check --select "TD" black_it tests examples scripts ```
To reproduce the errors: ``` ruff check --select "ERA" black_it tests examples scripts ``` We decided to ignore the errors in the examples/ code because they might be useful as inlined code documentation.
To reproduce the errors: ``` ruff check --select "PD" black_it tests examples scripts ```
To reproduce the errors: ``` ruff check --select "PGH" black_it tests examples scripts ```
To reproduce the errors: ``` ruff check --select "PLR2004" black_it tests examples scripts ``` We tried to not ignore errors as much as possible. This kind of error in the test files do not make much sense (expected values are usually "magic values" in code to make the tests more readable). Other errors were fixed by either replacing floats to ints (e.g. 0.0 -> 0, 1.0 -> 1), or moving the magic value to a module-level private constant.
To reproduce errors: ``` ruff check --select "PL" black_it tests examples scripts\n ```
To reproduce the errors: ``` ruff check --select "TRY" black_it tests examples scripts ```
To reproduce the above errors (the output will include also others): ``` ruff check --select "NPY" black_it tests examples scripts\n ``` In this commit, we explicitly ignored these errors: - examples/models/economics/boltzmann_wealth.py:93, we kept np.random.binomial since would have required a change in the APIs. This could be addressed separately in another commit.
marcofavoritobi
force-pushed
the
ruff
branch
2 times, most recently
from
September 21, 2023 11:57
5e920ca
to
e3dccc3
Compare
To reproduce the errors: ``` ruff check --select "NPY" examples/models/economics/brock_hommes.py ``` We also added tests to ensure reproducibility with fixed seed.
The fixes changed the behaviour of the models even if the same seed was fed before and after the changes. To reproduce: ``` import numpy as np from scipy.stats import alpha, bernoulli np.random.seed(0) print("NP.RANDOM") print(bernoulli.rvs(0.5, size=1)) print(bernoulli.rvs(0.5, size=1)) print("RNG") rng = np.random.default_rng(seed=0) print(bernoulli.rvs(0.5, size=1, random_state=rng)) print(bernoulli.rvs(0.5, size=1, random_state=rng)) ``` Output: ``` NP.RANDOM [1] [1] RNG [1] [0] ```
Fixed NPY002 issues in SIR models implemented in examples/models/sir/sir_python.py. Added tests to verify the new seed management works.
To reproduce the errors: ``` ruff check --select "NPY" tests ``` This commit updates the tests code so to make them to use np.random.default_rng with a certain seed, rather than relying on global random seed handling, i.e. using np.random.seed. To do so, a new fixture, 'rng', has been added so to avoid the tests code to initialize a np.random.Generator instance manually. This allowed to remove the special case for macOS platforms in TestCalibrate.test_calibrator_calibrate tests (but not for Windows).
To reproduce the errors: ``` ruff check --select "PERF" black_it tests examples scripts ```
To reproduce the changes: ``` ruff check --fix black_it tests examples scripts make black ruff check --fix black_it tests examples scripts ```
…_init__ A good practice is to use the coarsest type as argument function, so to make it usable in more ways. In particular, in this commit, the argument coordinate_filters in the base constructor of the class BaseLoss has been changed from 'list' to 'Sequence'. This allows to use coordinate_filters as tuples. It is also a more correct type hint, since coordinate_filters should not change during the lifetime of BaseLoss.
marcofavoritobi
force-pushed
the
ruff
branch
from
September 21, 2023 12:22
f60f40e
to
21c532e
Compare
To reproduce errors: ``` ruff check --show-fixes --fix black_it tests examples scripts ```
marcofavoritobi
force-pushed
the
ruff
branch
from
September 21, 2023 12:30
21c532e
to
355e44b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
This PR includes Ruff linter in the development and CI workflows. It subsumes other linters such as
flake8
,pylint
,isort
etc. in a single and efficient tool.The PR was structured so to apply the changes incrementally, aiming at guaranteeing the integrity of the intermediate states of the software, by handling one family of rules at a time. If the changes were too complex for a single family of rules, the changes were split into multiple commits.