Skip to content

Commit

Permalink
Add NPY rules to ruff. Solve NPY002
Browse files Browse the repository at this point in the history
The assert in the test that changes in this diff is just
due to the change of the way of setting the seed.
  • Loading branch information
berland committed Jul 2, 2024
1 parent 502a6d6 commit 02f5e1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ select = [
"F", # pyflakes
"C4", # flake8-comprehensions
"PL", # pylint
"NPY", # numpy specific rules
]
ignore = ["PLW2901", # redefined-loop-name
"PLR2004", # magic-value-comparison
Expand Down
12 changes: 6 additions & 6 deletions tests/workflows/ahm_analysis/test_ahm_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,25 @@ def test_calc_kolmogorov_smirnov():
ks_matrix = pd.DataFrame()
dkeys = ["param1", "param2"]
ks_matrix = pd.DataFrame(sorted(dkeys), columns=["Parameters"])
np.random.seed(12345678)
rng = np.random.default_rng(12345678)
prior_data = pd.DataFrame(
{
"param1": stats.norm.rvs(size=100, loc=0, scale=1),
"param2": stats.norm.rvs(size=100, loc=0.01, scale=1),
"param1": stats.norm.rvs(size=100, loc=0, scale=1, random_state=rng),
"param2": stats.norm.rvs(size=100, loc=0.01, scale=1, random_state=rng),
}
)
target_data = pd.DataFrame(
{
"param1": stats.norm.rvs(size=200, loc=0.5, scale=1.5),
"param2": stats.norm.rvs(size=200, loc=0.1, scale=1),
"param1": stats.norm.rvs(size=200, loc=0.5, scale=1.5, random_state=rng),
"param2": stats.norm.rvs(size=200, loc=0.1, scale=1, random_state=rng),
}
)
ks_matrix["WOPT:W1"] = ks_matrix["Parameters"].map(
ahmanalysis.calc_kolmogorov_smirnov(dkeys, prior_data, target_data)
)
ks_matrix.set_index("Parameters", inplace=True)
assert "param2" in ks_matrix.index
assert ks_matrix.loc["param1", "WOPT:W1"] == 0.18
assert ks_matrix.loc["param1", "WOPT:W1"] == 0.275
assert ks_matrix["WOPT:W1"].max() <= 1
assert ks_matrix["WOPT:W1"].min() >= 0

Expand Down

0 comments on commit 02f5e1e

Please sign in to comment.