From 95bb0985e7a364828322499dda55875c1334982b Mon Sep 17 00:00:00 2001 From: mbsantiago Date: Sun, 10 Nov 2024 19:13:11 +0000 Subject: [PATCH 1/3] Add ruff rule to help migrating to numpy 2.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c2b3ce2..a9399ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ docstring-code-format = true docstring-code-line-length = 79 [tool.ruff.lint] -select = ["E4", "E7", "E9", "F", "B", "Q", "I"] +select = ["E4", "E7", "E9", "F", "B", "Q", "I", "NPY201"] [tool.ruff.lint.pydocstyle] convention = "numpy" From 9e0ad7fd7820f488557c457784c96247147fc5be Mon Sep 17 00:00:00 2001 From: mbsantiago Date: Sun, 10 Nov 2024 19:13:30 +0000 Subject: [PATCH 2/3] address all linting errors from rule NPY201 --- batdetect2/utils/detector_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/batdetect2/utils/detector_utils.py b/batdetect2/utils/detector_utils.py index 8d6ca7f..bb613eb 100644 --- a/batdetect2/utils/detector_utils.py +++ b/batdetect2/utils/detector_utils.py @@ -8,6 +8,11 @@ import torch import torch.nn.functional as F +try: + from numpy.exceptions import AxisError +except ImportError: + from numpy import AxisError + import batdetect2.detector.compute_features as feats import batdetect2.detector.post_process as pp import batdetect2.utils.audio_utils as au @@ -242,7 +247,7 @@ def format_single_result( ) class_name = class_names[np.argmax(class_overall)] annotations = get_annotations_from_preds(predictions, class_names) - except (np.AxisError, ValueError): + except (AxisError, ValueError): # No detections class_overall = np.zeros(len(class_names)) class_name = "None" From 1ac3808fee12acd555f5ada403a180c7b8c71de6 Mon Sep 17 00:00:00 2001 From: mbsantiago Date: Sun, 10 Nov 2024 19:13:44 +0000 Subject: [PATCH 3/3] Remove the numpy<2 requirement from the dependencies specification --- pyproject.toml | 2 +- uv.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a9399ba..6283e3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ dependencies = [ "click>=8.1.7", "librosa>=0.10.1", "matplotlib>=3.7.1", - "numpy>=1.23.5,<2", + "numpy>=1.23.5", "pandas>=1.5.3", "scikit-learn>=1.2.2", "scipy>=1.10.1", diff --git a/uv.lock b/uv.lock index 73b36dd..69ccc11 100644 --- a/uv.lock +++ b/uv.lock @@ -45,7 +45,7 @@ requires-dist = [ { name = "click", specifier = ">=8.1.7" }, { name = "librosa", specifier = ">=0.10.1" }, { name = "matplotlib", specifier = ">=3.7.1" }, - { name = "numpy", specifier = ">=1.23.5,<2" }, + { name = "numpy", specifier = ">=1.23.5" }, { name = "pandas", specifier = ">=1.5.3" }, { name = "scikit-learn", specifier = ">=1.2.2" }, { name = "scipy", specifier = ">=1.10.1" },