From d7d19d0794f9f30e2c0b95752f7876a47608f1f0 Mon Sep 17 00:00:00 2001 From: Yann Leprince Date: Tue, 2 Jul 2024 16:17:03 +0200 Subject: [PATCH] remove use of deprecated NumPy APIs --- experimental/off_to_vtk.py | 2 +- pyproject.toml | 2 +- setup.cfg | 2 +- unit_tests/test_data_types.py | 9 ++++----- unit_tests/test_volume_reader.py | 8 +++----- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/experimental/off_to_vtk.py b/experimental/off_to_vtk.py index 4e3b880..9402cb4 100755 --- a/experimental/off_to_vtk.py +++ b/experimental/off_to_vtk.py @@ -32,7 +32,7 @@ def off_mesh_file_to_vtk(input_filename, output_filename, data_format="binary", assert match num_vertices = int(match.group(1)) num_triangles = int(match.group(2)) - vertices = np.empty((num_vertices, 3), dtype=np.float) + vertices = np.empty((num_vertices, 3), dtype=float) for i in range(num_vertices): components = f.readline().split() assert len(components) >= 3 diff --git a/pyproject.toml b/pyproject.toml index e1a4d85..1fdb591 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ extend-select = [ "W", "I", "N", - "NPY201", + "NPY", ] ignore = [ "N802", # Gives false positives when a name contains an uppercase acronym diff --git a/setup.cfg b/setup.cfg index 5a95e12..422fc5b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ packages = find: python_requires = ~=3.6 install_requires = nibabel >= 2 - numpy >= 1.11.0 + numpy >= 1.17 pillow >= 1.1.6 requests >= 2 scikit-image # TODO use pillow instead diff --git a/unit_tests/test_data_types.py b/unit_tests/test_data_types.py index cd918ec..38c2eef 100644 --- a/unit_tests/test_data_types.py +++ b/unit_tests/test_data_types.py @@ -135,9 +135,8 @@ def test_dtype_conversion_integer_downcasting(dtype): def test_unsupported_tupled_dtype(): - - random_val = np.random.rand(81).reshape((3, 3, 3, 3)) * 255 - random_val = random_val.astype(np.uint8) + rng = np.random.default_rng() + random_val = rng.integers(256, size=(3, 3, 3, 3), dtype=np.uint8) wrong_type = np.dtype([('A', 'u1'), ('B', 'u1'), ('C', 'u1')]) new_data = random_val.copy().view(dtype=wrong_type).reshape((3, 3, 3)) @@ -146,8 +145,8 @@ def test_unsupported_tupled_dtype(): def test_supported_tupled_dtype(): - random_val = np.random.rand(81).reshape((3, 3, 3, 3)) * 255 - random_val = random_val.astype(np.uint8) + rng = np.random.default_rng() + random_val = rng.integers(256, size=(3, 3, 3, 3), dtype=np.uint8) right_type = np.dtype([('R', 'u1'), ('G', 'u1'), ('B', 'u1')]) new_data = random_val.copy().view(dtype=right_type).reshape((3, 3, 3)) dtype, isrgb = get_dtype(new_data.dtype) diff --git a/unit_tests/test_volume_reader.py b/unit_tests/test_volume_reader.py index 10d38f4..06e1d2c 100644 --- a/unit_tests/test_volume_reader.py +++ b/unit_tests/test_volume_reader.py @@ -11,15 +11,13 @@ def prepare_nifti_images(): - - random_rgb_val = np.random.rand(81).reshape((3, 3, 3, 3)) * 255 - random_rgb_val = random_rgb_val.astype(np.uint8) + rng = np.random.default_rng() + random_rgb_val = rng.integers(256, size=(3, 3, 3, 3), dtype=np.uint8) right_type = np.dtype([("R", "u1"), ("G", "u1"), ("B", "u1")]) new_data = random_rgb_val.copy().view(dtype=right_type).reshape((3, 3, 3)) rgb_img = nib.Nifti1Image(new_data, np.eye(4)) - random_uint8_val = np.random.rand(27).reshape((3, 3, 3)) * 255 - random_uint8_val = random_uint8_val.astype(np.uint8) + random_uint8_val = rng.integers(256, size=(3, 3, 3), dtype=np.uint8) uint8_img = nib.Nifti1Image(random_uint8_val, np.eye(4)) return [(rgb_img, 3), (uint8_img, 1)]