Skip to content

Commit

Permalink
Fix NumPy 2.0 rule for np.alltrue and np.sometrue (#12473)
Browse files Browse the repository at this point in the history
Co-authored-by: Micha Reiser <micha@reiser.io>
  • Loading branch information
mtsokol and MichaReiser committed Jul 23, 2024
1 parent b9b7def commit f96a3c7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
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

0 comments on commit f96a3c7

Please sign in to comment.