-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fix ruff
NPY002
#162
Fix ruff
NPY002
#162
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,16 @@ | |
|
||
# %% Sankey diagram of random integers | ||
cols = ["col_a", "col_b"] | ||
df_rand_ints = pd.DataFrame(np.random.randint(1, 6, size=(100, 2)), columns=cols) | ||
np_rng = np.random.default_rng(seed=0) | ||
df_rand_ints = pd.DataFrame(np_rng.randint(1, 6, size=(100, 2)), columns=cols) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
fig = sankey_from_2_df_cols(df_rand_ints, cols, labels_with_counts="percent") | ||
rand_int_title = "Two sets of 100 random integers from 1 to 5" | ||
fig.update_layout(title=dict(text=rand_int_title, x=0.5, y=0.87)) | ||
code_anno = dict( | ||
x=0.5, | ||
y=-0.2, | ||
text="<span style='font-family: monospace;'>df = pd.DataFrame(" | ||
"np.random.randint(1, 6, size=(100, 2)), columns=['col_a','col_b'])<br>" | ||
"np_rng.randint(1, 6, size=(100, 2)), columns=['col_a','col_b'])<br>" | ||
"fig = sankey_from_2_df_cols(df, df.columns)</span>", | ||
font_size=12, | ||
showarrow=False, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,10 @@ | |
|
||
# %% Random regression data | ||
rand_regression_size = 500 | ||
y_true = np.random.normal(5, 4, rand_regression_size) | ||
y_pred = 1.2 * y_true - 2 * np.random.normal(0, 1, rand_regression_size) | ||
y_std = (y_true - y_pred) * 10 * np.random.normal(0, 0.1, rand_regression_size) | ||
np_rng = np.random.default_rng(seed=0) | ||
y_true = np_rng.normal(5, 4, rand_regression_size) | ||
y_pred = 1.2 * y_true - 2 * np_rng.normal(0, 1, rand_regression_size) | ||
y_std = (y_true - y_pred) * 10 * np_rng.normal(0, 0.1, rand_regression_size) | ||
|
||
|
||
# %% Uncertainty Plots | ||
|
@@ -27,7 +28,7 @@ | |
ax = error_decay_with_uncert(y_true, y_pred, y_std) | ||
save_and_compress_svg(ax, "error-decay-with-uncert") | ||
|
||
eps = 0.2 * np.random.randn(*y_std.shape) | ||
eps = 0.2 * np_rng.randn(*y_std.shape) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, should be |
||
|
||
ax = error_decay_with_uncert(y_true, y_pred, {"better": y_std, "worse": y_std + eps}) | ||
save_and_compress_svg(ax, "error-decay-with-uncert-multiple") | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janosh It's so interesting, as I started working on fixing
NPY002
violations inpymatgen
materialsproject/pymatgen#3892 without looking at this PR (really!) almost at the same time.But this legacy to new Generator replacement is not just replacing
np.random
withrng
(the API is not exactly the same, please refer to https://numpy.org/doc/stable/reference/random/generator.html), this should benp_rng.standard_normal(100)
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! thanks for letting me know. i should really take the time to make these scripts run in CI to avoid such mistakes...
will submit a fix now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem at all :) Yes we need to include them into CI tests, mind letting me (learn and) do this?