Skip to content

Commit

Permalink
More NPY201 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jun 28, 2024
1 parent c848712 commit 0420ed1
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/numpy/NPY201_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def func():
import numpy as np

np.DTypePromotionError

np.ModuleDeprecationWarning

np.RankWarning

np.TooHardError

np.VisibleDeprecationWarning

np.chararray

np.format_parser
2 changes: 2 additions & 0 deletions crates/ruff_linter/src/rules/numpy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ mod tests {
#[test_case(Rule::NumpyDeprecatedTypeAlias, Path::new("NPY001.py"))]
#[test_case(Rule::NumpyLegacyRandom, Path::new("NPY002.py"))]
#[test_case(Rule::NumpyDeprecatedFunction, Path::new("NPY003.py"))]
// The NPY201 tests are split into multiple files because they get fixed one by one and too many diagnostic exceed the max-iterations limit.
#[test_case(Rule::Numpy2Deprecation, Path::new("NPY201.py"))]
#[test_case(Rule::Numpy2Deprecation, Path::new("NPY201_2.py"))]
#[test_case(Rule::Numpy2Deprecation, Path::new("NPY201_3.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
let diagnostics = test_path(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
---
source: crates/ruff_linter/src/rules/numpy/mod.rs
---
NPY201_3.py:4:5: NPY201 [*] `np.DTypePromotionError` will be removed in NumPy 2.0. Use `numpy.exceptions.DTypePromotionError` instead.
|
2 | import numpy as np
3 |
4 | np.DTypePromotionError
| ^^^^^^^^^^^^^^^^^^^^^^ NPY201
5 |
6 | np.ModuleDeprecationWarning
|
= help: Replace with `numpy.exceptions.DTypePromotionError`

Safe fix
1 |+from numpy.exceptions import DTypePromotionError
1 2 | def func():
2 3 | import numpy as np
3 4 |
4 |- np.DTypePromotionError
5 |+ DTypePromotionError
5 6 |
6 7 | np.ModuleDeprecationWarning
7 8 |

NPY201_3.py:6:5: NPY201 [*] `np.ModuleDeprecationWarning` will be removed in NumPy 2.0. Use `numpy.exceptions.ModuleDeprecationWarning` instead.
|
4 | np.DTypePromotionError
5 |
6 | np.ModuleDeprecationWarning
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY201
7 |
8 | np.RankWarning
|
= help: Replace with `numpy.exceptions.ModuleDeprecationWarning`

Safe fix
1 |+from numpy.exceptions import ModuleDeprecationWarning
1 2 | def func():
2 3 | import numpy as np
3 4 |
4 5 | np.DTypePromotionError
5 6 |
6 |- np.ModuleDeprecationWarning
7 |+ ModuleDeprecationWarning
7 8 |
8 9 | np.RankWarning
9 10 |

NPY201_3.py:8:5: NPY201 [*] `np.RankWarning` will be removed in NumPy 2.0. Use `numpy.exceptions.RankWarning` on NumPy 2.0, or ignore this warning on earlier versions.
|
6 | np.ModuleDeprecationWarning
7 |
8 | np.RankWarning
| ^^^^^^^^^^^^^^ NPY201
9 |
10 | np.TooHardError
|
= help: Replace with `numpy.exceptions.RankWarning` (requires NumPy 2.0 or greater)

Unsafe fix
1 |+from numpy.exceptions import RankWarning
1 2 | def func():
2 3 | import numpy as np
3 4 |
--------------------------------------------------------------------------------
5 6 |
6 7 | np.ModuleDeprecationWarning
7 8 |
8 |- np.RankWarning
9 |+ RankWarning
9 10 |
10 11 | np.TooHardError
11 12 |

NPY201_3.py:10:5: NPY201 [*] `np.TooHardError` will be removed in NumPy 2.0. Use `numpy.exceptions.TooHardError` instead.
|
8 | np.RankWarning
9 |
10 | np.TooHardError
| ^^^^^^^^^^^^^^^ NPY201
11 |
12 | np.VisibleDeprecationWarning
|
= help: Replace with `numpy.exceptions.TooHardError`

Safe fix
1 |+from numpy.exceptions import TooHardError
1 2 | def func():
2 3 | import numpy as np
3 4 |
--------------------------------------------------------------------------------
7 8 |
8 9 | np.RankWarning
9 10 |
10 |- np.TooHardError
11 |+ TooHardError
11 12 |
12 13 | np.VisibleDeprecationWarning
13 14 |

NPY201_3.py:12:5: NPY201 [*] `np.VisibleDeprecationWarning` will be removed in NumPy 2.0. Use `numpy.exceptions.VisibleDeprecationWarning` instead.
|
10 | np.TooHardError
11 |
12 | np.VisibleDeprecationWarning
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY201
13 |
14 | np.chararray
|
= help: Replace with `numpy.exceptions.VisibleDeprecationWarning`

Safe fix
1 |+from numpy.exceptions import VisibleDeprecationWarning
1 2 | def func():
2 3 | import numpy as np
3 4 |
--------------------------------------------------------------------------------
9 10 |
10 11 | np.TooHardError
11 12 |
12 |- np.VisibleDeprecationWarning
13 |+ VisibleDeprecationWarning
13 14 |
14 15 | np.chararray
15 16 |

NPY201_3.py:14:5: NPY201 [*] `np.chararray` will be removed in NumPy 2.0. Use `numpy.char.chararray` instead.
|
12 | np.VisibleDeprecationWarning
13 |
14 | np.chararray
| ^^^^^^^^^^^^ NPY201
15 |
16 | np.format_parser
|
= help: Replace with `numpy.char.chararray`

Safe fix
1 |+from numpy.char import chararray
1 2 | def func():
2 3 | import numpy as np
3 4 |
--------------------------------------------------------------------------------
11 12 |
12 13 | np.VisibleDeprecationWarning
13 14 |
14 |- np.chararray
15 |+ chararray
15 16 |
16 17 | np.format_parser

NPY201_3.py:16:5: NPY201 [*] `np.format_parser` will be removed in NumPy 2.0. Use `numpy.rec.format_parser` instead.
|
14 | np.chararray
15 |
16 | np.format_parser
| ^^^^^^^^^^^^^^^^ NPY201
|
= help: Replace with `numpy.rec.format_parser`

Safe fix
1 |+from numpy.rec import format_parser
1 2 | def func():
2 3 | import numpy as np
3 4 |
--------------------------------------------------------------------------------
13 14 |
14 15 | np.chararray
15 16 |
16 |- np.format_parser
17 |+ format_parser

0 comments on commit 0420ed1

Please sign in to comment.