Repository: pyfar/pyfar
Pull request #629 (2024-06-15 13:10:25)

hotfix numpy>=2.0
- np.VisibleDeprecationWarning -> np.exceptions.VisibleDeprecationWarning https://numpy.org/devdocs/release/2.0.0-notes.html#numpy-2-0-python-api-removals
- tuple was returned as (np.int64(4), np.int64(5)) instead of (4, 5) it is fixed now.
- python 3.8 is not supported for numpy>=1.25, with this changes pyfar is still compatible to numpy 1.24..
- it was tests for numpy 2.0 nad numpy < 2.0 for all supported python version in pyfar

- installation of pyfar will not work with numpy == 2.0 for now, since the import of the ``VisibleDeprecationWarning`` will fail
fixes  #630



f-brinkmann: Maybe squash the commits before we merge?
f-brinkmann: @mberz, @ahms5 maybe release this as is as a patch and discuss, if we want to restrict to numpy>=1.25 and python>=3.9 during the next weekly?
mberz: Yes, that would be my suggestion as well. I'd prefer to not make the version jump in the minimum required numpy and hence Python version within a patch release.
@ahms5 So it's only the missing space 🤣 


Patch:
diff --git a/pyfar/classes/orientations.py b/pyfar/classes/orientations.py
index c73271bc..48cb5a95 100644
--- a/pyfar/classes/orientations.py
+++ b/pyfar/classes/orientations.py
@@ -3,11 +3,15 @@ import numpy as np
 import warnings
 
 import pyfar as pf
+if np.__version__ < '2.0.0':
+    from numpy import VisibleDeprecationWarning
+else:
+    from numpy.exceptions import VisibleDeprecationWarning
 
 # this warning needs to be caught and appears if numpy array are generated
 # from nested lists containing lists of unequal lengths, e.g.,
 #  [[1, 0, 0], [1, 0]]
-warnings.filterwarnings("error", category=np.VisibleDeprecationWarning)
+warnings.filterwarnings("error", category=VisibleDeprecationWarning)
 
 
 class Orientations(Rotation):
@@ -92,7 +96,7 @@ class Orientations(Rotation):
         try:
             views = np.atleast_2d(views).astype(np.float64)
             ups = np.atleast_2d(ups).astype(np.float64)
-        except np.VisibleDeprecationWarning:
+        except VisibleDeprecationWarning:
             raise ValueError("Expected `views` and `ups` to have shape (N, 3)")
 
         # check views and ups
diff --git a/pyfar/dsp/dsp.py b/pyfar/dsp/dsp.py
index 887f1cd1..5a97b0e3 100644
--- a/pyfar/dsp/dsp.py
+++ b/pyfar/dsp/dsp.py
@@ -524,8 +524,11 @@ def time_window(signal, interval, window='hann', shape='symmetric',
                 window_zeropadded, signal_win.sampling_rate)
 
     if return_window:
+        interval_str = str(tuple(interval))
+        if 'np' in interval_str:
+            interval_str = f"({', '.join([str(i) for i in interval])})"
         window_fin.comment = (
-            f"Time window with parameters interval={tuple(interval)},"
+            f"Time window with parameters interval={interval_str}, "
             f"window='{window}', shape='{shape}', unit='{unit}', "
             f"crop='{crop}'")
         return signal_win, window_fin


Test patch:
diff --git a/tests/test_dsp.py b/tests/test_dsp.py
index cbc7e27f..0788f5f0 100644
--- a/tests/test_dsp.py
+++ b/tests/test_dsp.py
@@ -529,10 +529,12 @@ def test_time_window_return_window(crop):
     assert isinstance(win, pyfar.Signal)
     assert sig_win.sampling_rate == win.sampling_rate
     npt.assert_allclose(sig_win.time, win.time)
-    desired_comment = (
-        f"Time window with parameters interval=(4, 8),"
-        f"window='hann', shape='symmetric', unit='samples', crop='{crop}'")
-    assert win.comment == desired_comment
+    assert 'interval=(4, 8)' in win.comment
+    assert "window='hann'," in win.comment
+    assert "shape='symmetric'," in win.comment
+    assert "unit='samples'," in win.comment
+    assert f"crop='{crop}'" in win.comment
+    assert 'Time window with parameters' in win.comment
 
 
 def test_time_window_return_window_error():