From 4934a14448444832d96de6f230fd72d33d2f862c Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Fri, 5 Apr 2024 14:51:11 +0100 Subject: [PATCH] Fix test suite for Numpy 2 (#1156) The only change needed was a now-removed alias. Also fix a typo in a test file's name that otherwise took me literally 6 goes to type even with tab completion. --- tests/digraph/test_adjacency_matrix.py | 8 ++++---- ...test_adjencency_matrix.py => test_adjacency_matrix.py} | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename tests/graph/{test_adjencency_matrix.py => test_adjacency_matrix.py} (98%) diff --git a/tests/digraph/test_adjacency_matrix.py b/tests/digraph/test_adjacency_matrix.py index 38d998559..7b85a31ef 100644 --- a/tests/digraph/test_adjacency_matrix.py +++ b/tests/digraph/test_adjacency_matrix.py @@ -153,10 +153,10 @@ def test_random_graph_float_dtype(self): def test_non_zero_null(self): input_matrix = np.array( - [[np.Inf, 1, np.Inf], [1, np.Inf, 1], [np.Inf, 1, np.Inf]], + [[np.inf, 1, np.inf], [1, np.inf, 1], [np.inf, 1, np.inf]], dtype=np.float64, ) - graph = rustworkx.PyDiGraph.from_adjacency_matrix(input_matrix, null_value=np.Inf) + graph = rustworkx.PyDiGraph.from_adjacency_matrix(input_matrix, null_value=np.inf) adj_matrix = rustworkx.adjacency_matrix(graph, float) expected_matrix = np.array( [[0.0, 1.0, 0.0], [1.0, 0.0, 1.0], [0.0, 1.0, 0.0]], @@ -231,10 +231,10 @@ def test_random_graph_complex_dtype(self): def test_non_zero_null(self): input_matrix = np.array( - [[np.Inf, 1, np.Inf], [1, np.Inf, 1], [np.Inf, 1, np.Inf]], + [[np.inf, 1, np.inf], [1, np.inf, 1], [np.inf, 1, np.inf]], dtype=np.complex128, ) - graph = rustworkx.PyDiGraph.from_complex_adjacency_matrix(input_matrix, null_value=np.Inf) + graph = rustworkx.PyDiGraph.from_complex_adjacency_matrix(input_matrix, null_value=np.inf) expected = [ (0, 1, 1 + 0j), (1, 0, 1 + 0j), diff --git a/tests/graph/test_adjencency_matrix.py b/tests/graph/test_adjacency_matrix.py similarity index 98% rename from tests/graph/test_adjencency_matrix.py rename to tests/graph/test_adjacency_matrix.py index d303c7550..4944ea418 100644 --- a/tests/graph/test_adjencency_matrix.py +++ b/tests/graph/test_adjacency_matrix.py @@ -165,10 +165,10 @@ def test_graph_to_digraph_adjacency_matrix(self): def test_non_zero_null(self): input_matrix = np.array( - [[np.Inf, 1, np.Inf], [1, np.Inf, 1], [np.Inf, 1, np.Inf]], + [[np.inf, 1, np.inf], [1, np.inf, 1], [np.inf, 1, np.inf]], dtype=np.float64, ) - graph = rustworkx.PyGraph.from_adjacency_matrix(input_matrix, null_value=np.Inf) + graph = rustworkx.PyGraph.from_adjacency_matrix(input_matrix, null_value=np.inf) adj_matrix = rustworkx.adjacency_matrix(graph, float) expected_matrix = np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]], dtype=np.float64) self.assertTrue(np.array_equal(adj_matrix, expected_matrix)) @@ -231,10 +231,10 @@ def test_random_graph_complex_dtype(self): def test_non_zero_null(self): input_matrix = np.array( - [[np.Inf, 1, np.Inf], [1, np.Inf, 1], [np.Inf, 1, np.Inf]], + [[np.inf, 1, np.inf], [1, np.inf, 1], [np.inf, 1, np.inf]], dtype=np.complex128, ) - graph = rustworkx.PyGraph.from_complex_adjacency_matrix(input_matrix, null_value=np.Inf) + graph = rustworkx.PyGraph.from_complex_adjacency_matrix(input_matrix, null_value=np.inf) expected = [ (0, 1, 1 + 0j), (1, 2, 1 + 0j), From a6c9849e61228be20158dee03fe687456cbb3022 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 26 Apr 2024 20:42:45 -0400 Subject: [PATCH] Relax numpy upper version cap (#1172) * Relax numpy upper version cap In #1012 we added an upper version cap to numpy to prevent it from installing numpy 2.0 before we confirmed that rustworkx was compatible with it. Now that numpy 2.0.0rc1 has been released we're able to confirm that rustworkx works fine with numpy 2.0. This commit raises the upper bound on the numpy version to < 3 to enable installing numpy 2.0 with rustworkx. * Handle new __array__ API in numpy 2.0 While we didn't have any test coverage for this looking at the numpy 2.0 migration guide one thing we'll have to handle is the new copy kwarg on array: https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword This commit updates the sole use of __array__ we have on custom sequence return types so that if copy=False is passed in we raise a ValueError. Additionally, the dtype handling is done directly in the rustworkx code now to ensure we don't have any issues with numpy 2.0. * Fix __array__ stubs * Update src/iterators.rs * Pin ruff to 0.4.1 --------- Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com> --- .github/workflows/main.yml | 2 +- rustworkx/rustworkx.pyi | 2 +- setup.py | 2 +- src/iterators.rs | 28 ++++++++++++++++++++++------ tests/test_custom_return_types.py | 10 ++++++++++ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 82a390d7e..40bf25ca8 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def readme(): PKG_NAME = os.getenv("RUSTWORKX_PKG_NAME", "rustworkx") PKG_VERSION = "0.15.0" PKG_PACKAGES = ["rustworkx", "rustworkx.visualization"] -PKG_INSTALL_REQUIRES = ["numpy>=1.16.0,<2"] +PKG_INSTALL_REQUIRES = ["numpy>=1.16.0,<3"] RUST_EXTENSIONS = [RustExtension("rustworkx.rustworkx", "Cargo.toml", binding=Binding.PyO3, debug=rustworkx_debug)] RUST_OPTS ={"bdist_wheel": {"py_limited_api": "cp38"}}