From f44dad8a60aba13ff23c42b3094c76d222a2c6de Mon Sep 17 00:00:00 2001 From: Frank Loesche Date: Wed, 11 Dec 2024 10:08:31 -0500 Subject: [PATCH 1/5] =?UTF-8?q?np.float=5F=20=E2=86=92=20np.float64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit replace np.float_ with np.float64. The minimum numpy version 1.16 has both as aliases, the newer version numpy>=2.0 don't support np.float_ anymore. --- navis/plotting/plot_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/navis/plotting/plot_utils.py b/navis/plotting/plot_utils.py index de3fb31b..802bd382 100644 --- a/navis/plotting/plot_utils.py +++ b/navis/plotting/plot_utils.py @@ -190,7 +190,7 @@ def make_tube(segments, radii=1.0, tube_points=8, use_normals=True): faces : np.ndarray """ - vertices = np.empty((0, 3), dtype=np.float_) + vertices = np.empty((0, 3), dtype=np.float64) indices = np.empty((0, 3), dtype=np.uint32) if not isinstance(radii, Iterable): @@ -219,7 +219,7 @@ def make_tube(segments, radii=1.0, tube_points=8, use_normals=True): # Vertices for each point on the circle verts = np.repeat(points, tube_points, axis=0) - v = np.arange(tube_points, dtype=np.float_) / tube_points * 2 * np.pi + v = np.arange(tube_points, dtype=np.float64) / tube_points * 2 * np.pi all_cx = ( radius From bd0e2dccc68e469204e5046cbbedfefc719487da Mon Sep 17 00:00:00 2001 From: Frank Loesche Date: Wed, 11 Dec 2024 10:10:43 -0500 Subject: [PATCH 2/5] workaround for doctest comparison of np dtypes [NEP51](https://numpy.org/neps/nep-0051-scalar-representation.html#backward-compatibility) changes the representation of scalars. While the long term strategy should be a comparison with the new form of representation, the discussion in [issue 24470](https://github.com/numpy/numpy/issues/24470) seems to suggest to use an intermediate step while both, numpy-1 and numpy-2 are supported. --- navis/morpho/mmetrics.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/navis/morpho/mmetrics.py b/navis/morpho/mmetrics.py index dcd8c415..7864326e 100644 --- a/navis/morpho/mmetrics.py +++ b/navis/morpho/mmetrics.py @@ -30,6 +30,12 @@ # Set up logging logger = config.get_logger(__name__) +# Set up numpy number representation, see NEP51 +# Once numpy<=2 is dropped from requirements, the doctest comparissons +# should become `np.float64(1.074)` instead of `1.074` +if int(np.version.version.split('.')[0])>=2: + np.set_printoptions(legacy="1.25") + __all__ = sorted( [ "strahler_index", From 3f2d47e904413f7194d1210e599742029d61c2fd Mon Sep 17 00:00:00 2001 From: Frank Loesche Date: Mon, 16 Dec 2024 10:41:41 -0500 Subject: [PATCH 3/5] move number representation to test itself --- navis/morpho/mmetrics.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/navis/morpho/mmetrics.py b/navis/morpho/mmetrics.py index 7864326e..93a4feca 100644 --- a/navis/morpho/mmetrics.py +++ b/navis/morpho/mmetrics.py @@ -30,12 +30,6 @@ # Set up logging logger = config.get_logger(__name__) -# Set up numpy number representation, see NEP51 -# Once numpy<=2 is dropped from requirements, the doctest comparissons -# should become `np.float64(1.074)` instead of `1.074` -if int(np.version.version.split('.')[0])>=2: - np.set_printoptions(legacy="1.25") - __all__ = sorted( [ "strahler_index", @@ -1327,7 +1321,12 @@ def tortuosity( Examples -------- + (Set up numpy number representation within the test, see NEP51. + Once numpy<=2 is dropped from requirements, the doctest comparissons + should become `np.float64(1.074)` instead of `1.074`) >>> import navis + >>> if int(np.version.version.split('.')[0])>=2: + np.set_printoptions(legacy="1.25") >>> n = navis.example_neurons(1) >>> # Calculate tortuosity as-is >>> T = navis.tortuosity(n) From f5b45ab74f871ee28f82cb94c822e05f8530ff87 Mon Sep 17 00:00:00 2001 From: Frank Loesche Date: Mon, 16 Dec 2024 11:22:38 -0500 Subject: [PATCH 4/5] set test env to switch numpy representation --- .github/workflows/test-package.yml | 1 + navis/morpho/mmetrics.py | 12 +++++++----- pytest.ini | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index 00de485a..0a1da86b 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -58,4 +58,5 @@ jobs: with: run: | export NAVIS_HEADLESS=TRUE + export NAVIS_TEST_ENV=TRUE pytest --verbose diff --git a/navis/morpho/mmetrics.py b/navis/morpho/mmetrics.py index 93a4feca..d7986791 100644 --- a/navis/morpho/mmetrics.py +++ b/navis/morpho/mmetrics.py @@ -15,6 +15,7 @@ """This module contains functions to analyse and manipulate neuron morphology.""" import math +import os import itertools import scipy import warnings @@ -30,6 +31,12 @@ # Set up logging logger = config.get_logger(__name__) +# Set up numpy number representation, see NEP51 +# Once numpy<=2 is dropped from requirements, the doctest comparissons +# should become `np.float64(1.074)` instead of `1.074` +if os.environ.get('NAVIS_TEST_ENV', '').lower() == 'true': + np.set_printoptions(legacy="1.25") + __all__ = sorted( [ "strahler_index", @@ -1321,12 +1328,7 @@ def tortuosity( Examples -------- - (Set up numpy number representation within the test, see NEP51. - Once numpy<=2 is dropped from requirements, the doctest comparissons - should become `np.float64(1.074)` instead of `1.074`) >>> import navis - >>> if int(np.version.version.split('.')[0])>=2: - np.set_printoptions(legacy="1.25") >>> n = navis.example_neurons(1) >>> # Calculate tortuosity as-is >>> T = navis.tortuosity(n) diff --git a/pytest.ini b/pytest.ini index 6754b78f..f7278cac 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,3 +3,4 @@ doctest_optionflags = IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE addopts = --doctest-modules env = NAVIS_HEADLESS=TRUE + NAVIS_TEST_ENV=TRUE From 628c0c1bdbff6789740fb9f133611fd57a1af61e Mon Sep 17 00:00:00 2001 From: Frank Loesche Date: Mon, 16 Dec 2024 13:45:18 -0500 Subject: [PATCH 5/5] commiting the changes I described earlier in #176 --- navis/config.py | 6 ++++++ navis/morpho/mmetrics.py | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/navis/config.py b/navis/config.py index 9aec3b17..c675630d 100644 --- a/navis/config.py +++ b/navis/config.py @@ -59,6 +59,12 @@ def get_logger(name: str): return logging.getLogger(name) return logger +# Set up numpy number representation, see NEP51 +# Once numpy<=2 is dropped from requirements, the doctest comparissons +# should become `np.float64(1.074)` instead of `1.074` +if os.environ.get('NAVIS_TEST_ENV', '').lower() == 'true': + import numpy as np + np.set_printoptions(legacy="1.25") # Default settings for progress bars pbar_hide = False diff --git a/navis/morpho/mmetrics.py b/navis/morpho/mmetrics.py index d7986791..4e3ae951 100644 --- a/navis/morpho/mmetrics.py +++ b/navis/morpho/mmetrics.py @@ -15,7 +15,6 @@ """This module contains functions to analyse and manipulate neuron morphology.""" import math -import os import itertools import scipy import warnings @@ -31,11 +30,6 @@ # Set up logging logger = config.get_logger(__name__) -# Set up numpy number representation, see NEP51 -# Once numpy<=2 is dropped from requirements, the doctest comparissons -# should become `np.float64(1.074)` instead of `1.074` -if os.environ.get('NAVIS_TEST_ENV', '').lower() == 'true': - np.set_printoptions(legacy="1.25") __all__ = sorted( [