From b0845e54e5fb5de0b3bfda5d4e1abf8e0591930e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Sok=C3=B3=C5=82?= Date: Thu, 28 Mar 2024 10:57:31 +0100 Subject: [PATCH] Add row_stack to NumPy 2.0 migration rule --- .../resources/test/fixtures/numpy/NPY201.py | 2 ++ .../rules/numpy/rules/numpy_2_0_deprecation.rs | 8 ++++++++ ...py__tests__numpy2-deprecation_NPY201.py.snap | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/crates/ruff_linter/resources/test/fixtures/numpy/NPY201.py b/crates/ruff_linter/resources/test/fixtures/numpy/NPY201.py index 1143e1e7accc1d..c72301fed4f7e0 100644 --- a/crates/ruff_linter/resources/test/fixtures/numpy/NPY201.py +++ b/crates/ruff_linter/resources/test/fixtures/numpy/NPY201.py @@ -104,3 +104,5 @@ def func(): np.unicode_("asf") np.who() + + np.row_stack(([1,2], [3,4])) diff --git a/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs b/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs index b969ca5e6db070..561e19d0b3cc3b 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs @@ -522,6 +522,14 @@ pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) { guideline: Some("Use an IDE variable explorer or `locals()` instead."), }, }), + ["numpy", "row_stack"] => Some(Replacement { + existing: "row_stack", + details: Details::AutoImport { + path: "numpy", + name: "vstack", + compatibility: Compatibility::BackwardsCompatible, + }, + }), _ => None, }); diff --git a/crates/ruff_linter/src/rules/numpy/snapshots/ruff_linter__rules__numpy__tests__numpy2-deprecation_NPY201.py.snap b/crates/ruff_linter/src/rules/numpy/snapshots/ruff_linter__rules__numpy__tests__numpy2-deprecation_NPY201.py.snap index de184683eda295..37b6ac7eb29ad4 100644 --- a/crates/ruff_linter/src/rules/numpy/snapshots/ruff_linter__rules__numpy__tests__numpy2-deprecation_NPY201.py.snap +++ b/crates/ruff_linter/src/rules/numpy/snapshots/ruff_linter__rules__numpy__tests__numpy2-deprecation_NPY201.py.snap @@ -845,4 +845,21 @@ NPY201.py:106:5: NPY201 `np.who` will be removed in NumPy 2.0. Use an IDE variab | ^^^^^^ NPY201 | +NPY201.py:108:5: NPY201 [*] `np.row_stack` will be removed in NumPy 2.0. Use `numpy.vstack` instead. + | +106 | np.who() +107 | +108 | np.row_stack(([1,2], [3,4])) + | ^^^^^^^^^^^^ NPY201 + | + = help: Replace with `numpy.vstack` + +ℹ Safe fix +105 105 | +106 106 | np.who() +107 107 | +108 |- np.row_stack(([1,2], [3,4])) + 108 |+ np.vstack(([1,2], [3,4])) +109 109 | +