Skip to content
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 NumPy 2.0 rule for np.alltrue and np.sometrue #12473

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def func():

np.alltrue([True, True])

np.anytrue([True, False])
np.sometrue([True, False])

np.cumproduct([1, 2, 3])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) {
}),
["numpy", "alltrue"] => Some(Replacement {
existing: "alltrue",
details: Details::AutoPurePython {
python_expr: "all",
details: Details::AutoImport {
path: "numpy",
name: "all",
compatibility: Compatibility::BackwardsCompatible,
},
}),
["numpy", "asfarray"] => Some(Replacement {
Expand Down Expand Up @@ -524,8 +526,10 @@ pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) {
}),
["numpy", "sometrue"] => Some(Replacement {
existing: "sometrue",
details: Details::AutoPurePython {
python_expr: "any",
details: Details::AutoImport {
path: "numpy",
name: "any",
compatibility: Compatibility::BackwardsCompatible,
},
}),
["numpy", "source"] => Some(Replacement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,30 +306,51 @@ NPY201_2.py:40:5: NPY201 [*] `np.row_stack` will be removed in NumPy 2.0. Use `n
42 42 | np.alltrue([True, True])
43 43 |

NPY201_2.py:42:5: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
NPY201_2.py:42:5: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `numpy.all` instead.
|
40 | np.row_stack(([1,2], [3,4]))
41 |
42 | np.alltrue([True, True])
| ^^^^^^^^^^ NPY201
43 |
44 | np.anytrue([True, False])
44 | np.sometrue([True, False])
|
= help: Replace with `all`
= help: Replace with `numpy.all`

Safe fix
39 39 |
40 40 | np.row_stack(([1,2], [3,4]))
41 41 |
42 |- np.alltrue([True, True])
42 |+ all([True, True])
42 |+ np.all([True, True])
43 43 |
44 44 | np.anytrue([True, False])
44 44 | np.sometrue([True, False])
45 45 |

NPY201_2.py:44:5: NPY201 [*] `np.sometrue` will be removed in NumPy 2.0. Use `numpy.any` instead.
|
42 | np.alltrue([True, True])
43 |
44 | np.sometrue([True, False])
| ^^^^^^^^^^^ NPY201
45 |
46 | np.cumproduct([1, 2, 3])
|
= help: Replace with `numpy.any`

Safe fix
41 41 |
42 42 | np.alltrue([True, True])
43 43 |
44 |- np.sometrue([True, False])
44 |+ np.any([True, False])
45 45 |
46 46 | np.cumproduct([1, 2, 3])
47 47 |

NPY201_2.py:46:5: NPY201 [*] `np.cumproduct` will be removed in NumPy 2.0. Use `numpy.cumprod` instead.
|
44 | np.anytrue([True, False])
44 | np.sometrue([True, False])
45 |
46 | np.cumproduct([1, 2, 3])
| ^^^^^^^^^^^^^ NPY201
Expand All @@ -340,7 +361,7 @@ NPY201_2.py:46:5: NPY201 [*] `np.cumproduct` will be removed in NumPy 2.0. Use `

Safe fix
43 43 |
44 44 | np.anytrue([True, False])
44 44 | np.sometrue([True, False])
45 45 |
46 |- np.cumproduct([1, 2, 3])
46 |+ np.cumprod([1, 2, 3])
Expand Down
Loading