From 656fa647b4d771283f6212ed714a548b5142a04a Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Sat, 29 Jun 2024 15:26:48 +1000 Subject: [PATCH] Add numpy 2 compatibility (#229) Simply replaces uses of column_stack and row_stack with concatenate, since the arrays already had the desired shapes anyway. Closes #228 --- .github/workflows/test.yml | 6 +----- pyproject.toml | 4 ++-- src/skan/_testdata.py | 4 ++-- src/skan/csr.py | 2 +- src/skan/nputil.py | 4 ++-- src/skan/test/test_csr.py | 2 +- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98524fd3..76008eaf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,11 +21,7 @@ jobs: fail-fast: false matrix: platform: [ubuntu-latest, windows-latest, macos-latest] - python: [3.8, 3.9, "3.10"] - include: - # test big sur on 3.9.0 - - python: 3.9 - platform: macos-11.0 + python: ["3.9", "3.12"] steps: - uses: actions/checkout@v3 diff --git a/pyproject.toml b/pyproject.toml index eb0077a2..e4a1144c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,14 +38,14 @@ keywords = [ 'image processing', 'skeletons' ] -requires-python = '>=3.8' +requires-python = '>=3.9' dependencies = [ 'imageio>=2.10.1', 'magicgui>=0.7.3', 'matplotlib>=3.4', 'networkx>=2.7', 'numba>=0.53', - 'numpy>=1.21', + 'numpy>=1.25', 'pandas>=2.0.2', 'openpyxl>=2.6', 'scikit-image>=0.17.1', diff --git a/src/skan/_testdata.py b/src/skan/_testdata.py index 43b3e919..7d58ec8a 100644 --- a/src/skan/_testdata.py +++ b/src/skan/_testdata.py @@ -25,8 +25,8 @@ _zeros1 = np.zeros_like(skeleton1) -skeleton2 = np.column_stack((skeleton1, _zeros1)) -skeleton2 = np.row_stack((skeleton2, skeleton2[:, ::-1])) +skeleton2 = np.concatenate((skeleton1, _zeros1), axis=1) +skeleton2 = np.concatenate((skeleton2, skeleton2[:, ::-1]), axis=0) skeleton3d = np.array([[[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], diff --git a/src/skan/csr.py b/src/skan/csr.py index 18b7aad5..bc310f14 100644 --- a/src/skan/csr.py +++ b/src/skan/csr.py @@ -760,7 +760,7 @@ def summarize( "to silence this warning, use `separator='-'` to maintain " "current behavior and use `separator='_'` to switch to the " "new default behavior.", - np.VisibleDeprecationWarning, + np.exceptions.VisibleDeprecationWarning, stacklevel=2, # make sure warning points to calling line ) separator = '-' diff --git a/src/skan/nputil.py b/src/skan/nputil.py index 6b69eeee..1107b708 100644 --- a/src/skan/nputil.py +++ b/src/skan/nputil.py @@ -240,9 +240,9 @@ def _raveled_offsets_and_distances( ... ) >>> off # doctest: +SKIP array([-5, -1, 1, 5, -6, -4, 4, 6, 10, 9, 11]) - >>> d[0] + >>> float(d[0]) # avoid np.float64 repr 1.0 - >>> d[-1] # distance from (1, 1) to (3, 2) + >>> float(d[-1]) # distance from (1, 1) to (3, 2) 2.236... """ ndim = len(image_shape) diff --git a/src/skan/test/test_csr.py b/src/skan/test/test_csr.py index 246db331..2c937e62 100644 --- a/src/skan/test/test_csr.py +++ b/src/skan/test/test_csr.py @@ -358,7 +358,7 @@ def test_skeleton_integer_dtype(dtype): def test_default_summarize_separator(): - with pytest.warns(np.VisibleDeprecationWarning, + with pytest.warns(np.exceptions.VisibleDeprecationWarning, match='separator in column name'): stats = csr.summarize(csr.Skeleton(skeletonlabel)) assert 'skeleton-id' in stats