Fix NumPy 2.0 rule for `np.alltrue` and `np.sometrue` (#12473)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Mateusz Sokół 2024-07-23 10:34:43 +02:00 committed by GitHub
parent b9b7deff17
commit f96a3c71ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 12 deletions

View File

@ -41,7 +41,7 @@ def func():
np.alltrue([True, True])
np.anytrue([True, False])
np.sometrue([True, False])
np.cumproduct([1, 2, 3])

View File

@ -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 {
@ -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 {

View File

@ -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
@ -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])