From 01ca9a40bc551679e5b3bdc68c817e476ee337a8 Mon Sep 17 00:00:00 2001
From: Wolfgang Kastaun <wolfgang.kastaun@aei.mpg.de>
Date: Thu, 19 Dec 2024 17:49:37 +0100
Subject: [PATCH] Some cleanup to fix linting pipelines

---
 lisainstrument/fixed_shift_dask.py  |  8 +++----
 lisainstrument/fixed_shift_dsp.py   |  8 +++----
 lisainstrument/fixed_shift_numpy.py |  2 ++
 tests/test_fixed_shift_dask.py      | 27 ++++++++-------------
 tests/test_fixed_shift_numpy.py     | 37 ++++++++++++++---------------
 5 files changed, 37 insertions(+), 45 deletions(-)

diff --git a/lisainstrument/fixed_shift_dask.py b/lisainstrument/fixed_shift_dask.py
index 90edae7..7dcc277 100644
--- a/lisainstrument/fixed_shift_dask.py
+++ b/lisainstrument/fixed_shift_dask.py
@@ -64,8 +64,8 @@ class FixedShiftDask:  # pylint: disable=too-few-public-methods
                     )
                 case DynShiftBC.EXCEPTION:
                     msg = (
-                        f"FixedShiftDask: left edge handling {self._left_bound.name} not "
-                        f"possible for given delay, need margin of {margin_left}."
+                        f"FixedShiftDask: left edge handling {self._left_bound.name} "
+                        f"impossible for given delay, would need margin of {margin_left}."
                     )
                     raise RuntimeError(msg)
                 case _ as unreachable:
@@ -85,8 +85,8 @@ class FixedShiftDask:  # pylint: disable=too-few-public-methods
                     )
                 case DynShiftBC.EXCEPTION:
                     msg = (
-                        f"FixedShiftNumpy: right edge handling {self._right_bound.name} not "
-                        f"possible for given delay, need margin of {margin_right}."
+                        f"FixedShiftDask: right edge handling {self._right_bound.name} "
+                        f"impossible for given delay, would need margin of {margin_right}."
                     )
                     raise RuntimeError(msg)
                 case _ as unreachable:
diff --git a/lisainstrument/fixed_shift_dsp.py b/lisainstrument/fixed_shift_dsp.py
index 3d341cc..6cb5074 100644
--- a/lisainstrument/fixed_shift_dsp.py
+++ b/lisainstrument/fixed_shift_dsp.py
@@ -2,7 +2,7 @@
 
 There are two implementations of fixed-shift Lagrange interpolation:
 
-1. fixed_shift_dsp.make_fixed_shift_dsp wraps legacy implementation dsp.timeshift 
+1. fixed_shift_dsp.make_fixed_shift_dsp wraps legacy implementation dsp.timeshift
    into new interface
 2. fixed_shift_numpy.make_fixed_shift_lagrange provides a completely new implementation
    of Lagrange interpolation
@@ -17,15 +17,13 @@ from typing import Final
 import numpy as np
 
 from lisainstrument import dsp
-from lisainstrument.fixed_shift_dask import FixedShiftDask
 from lisainstrument.dynamic_delay_numpy import DynShiftBC
-
 from lisainstrument.fir_filters_numpy import NumpyArray1D, make_numpy_array_1d
-
+from lisainstrument.fixed_shift_dask import FixedShiftDask
 from lisainstrument.fixed_shift_numpy import (
-    make_numpy_array_1d_float,
     FixedShiftCore,
     FixedShiftFactory,
+    make_numpy_array_1d_float,
 )
 
 
diff --git a/lisainstrument/fixed_shift_numpy.py b/lisainstrument/fixed_shift_numpy.py
index 8b98393..e0b1a9e 100644
--- a/lisainstrument/fixed_shift_numpy.py
+++ b/lisainstrument/fixed_shift_numpy.py
@@ -334,9 +334,11 @@ class FixedShiftNumpy:  # pylint: disable=too-few-public-methods
             Numpy array with interpolated samples
         """
 
+        # pylint: disable=duplicate-code
         loc = -shift
         loc_int = int(np.floor(loc))
         loc_frac = loc - loc_int
+        # pylint: enable=duplicate-code
 
         interp = self._interp_fac(-loc_frac)
 
diff --git a/tests/test_fixed_shift_dask.py b/tests/test_fixed_shift_dask.py
index bc4177c..95296b5 100644
--- a/tests/test_fixed_shift_dask.py
+++ b/tests/test_fixed_shift_dask.py
@@ -1,11 +1,10 @@
 import numpy as np
 import pytest
 
-
-from lisainstrument.dynamic_delay_numpy import DynShiftBC
 from lisainstrument.dynamic_delay_dask import numpyfy_dask_multi
-from lisainstrument.fixed_shift_numpy import make_fixed_shift_lagrange_numpy
+from lisainstrument.dynamic_delay_numpy import DynShiftBC
 from lisainstrument.fixed_shift_dask import make_fixed_shift_lagrange_dask
+from lisainstrument.fixed_shift_numpy import make_fixed_shift_lagrange_numpy
 
 
 def test_fixed_shift_lagrange_dask() -> None:
@@ -27,7 +26,7 @@ def test_fixed_shift_lagrange_dask() -> None:
     y = g(t)
 
     for d in (0.93456456 / dt, 3.1, 3.5, 3.9, 4.0, 4.1, 4.5, 4.9, 116.0):
-        
+
         op_np = make_fixed_shift_lagrange_numpy(
             DynShiftBC.FLAT, DynShiftBC.EXCEPTION, length
         )
@@ -42,11 +41,9 @@ def test_fixed_shift_lagrange_dask() -> None:
 
         margin_ex = -int(np.floor(-d)) + order // 2
 
-        
         assert s_na == pytest.approx(s_np, rel=1e-14, abs=0)
         assert s_ex[margin_ex:] == pytest.approx(s_na[margin_ex:], abs=1e-15, rel=5e-13)
 
-        
         with pytest.raises(RuntimeError):
             op_na(y, -d)
 
@@ -68,21 +65,17 @@ def test_fixed_shift_lagrange_dask() -> None:
         assert s2_ex[:-margin2_ex] == pytest.approx(
             s2_na[:-margin2_ex], abs=1e-15, rel=5e-13
         )
-        
+
         with pytest.raises(RuntimeError):
             op2_na(y, d)
-            
+
         op3_da = make_fixed_shift_lagrange_dask(
             DynShiftBC.FLAT, DynShiftBC.FLAT, length
         )
-        op3_na = numpyfy_dask_multi(op3_da, chunks=113)    
-            
-        s3_na = op3_na(y, d)  
+        op3_na = numpyfy_dask_multi(op3_da, chunks=113)
+
+        s3_na = op3_na(y, d)
         assert s3_na == pytest.approx(s_np, rel=1e-14, abs=0)
-        
-        s4_na = op3_na(y, -d)  
+
+        s4_na = op3_na(y, -d)
         assert s4_na == pytest.approx(s2_np, rel=1e-14, abs=0)
-        
-        
-        
-        
diff --git a/tests/test_fixed_shift_numpy.py b/tests/test_fixed_shift_numpy.py
index 4b3a3a9..bfa90fc 100644
--- a/tests/test_fixed_shift_numpy.py
+++ b/tests/test_fixed_shift_numpy.py
@@ -1,9 +1,7 @@
 import numpy as np
 import pytest
 
-
 from lisainstrument.dynamic_delay_numpy import DynShiftBC
-
 from lisainstrument.fixed_shift_numpy import make_fixed_shift_lagrange_numpy
 
 
@@ -25,30 +23,31 @@ def test_fixed_shift_lagrange_dask() -> None:
 
     y = g(t)
 
-    for d in (0.93456456/dt, 3.1, 3.5, 3.9, 4.0, 4.1, 4.5, 4.9):
-    # ~ d = 0.93456456 / dt
-        
-        op_np = make_fixed_shift_lagrange_numpy(DynShiftBC.FLAT, DynShiftBC.EXCEPTION, length)
-        
+    for d in (0.93456456 / dt, 3.1, 3.5, 3.9, 4.0, 4.1, 4.5, 4.9):
+        # ~ d = 0.93456456 / dt
+
+        op_np = make_fixed_shift_lagrange_numpy(
+            DynShiftBC.FLAT, DynShiftBC.EXCEPTION, length
+        )
+
         s_np = op_np(y, d)
         s_ex = g(t - d * dt)
 
-        margin_ex = -int(np.floor(-d)) + order // 2 
-        
-        print(d, d*dt, margin_ex)
-        
-        assert s_ex[margin_ex:] == pytest.approx(
-            s_np[margin_ex:], abs=1e-15, rel=5e-13
-        )
+        margin_ex = -int(np.floor(-d)) + order // 2
+
+        print(d, d * dt, margin_ex)
+
+        assert s_ex[margin_ex:] == pytest.approx(s_np[margin_ex:], abs=1e-15, rel=5e-13)
 
         # ~ assert np.min(np.abs(s_ex[:margin_ex] - s_np[:margin_ex])) > np.max(np.abs(y[:margin_ex]))*1e-10
-        
+
         with pytest.raises(RuntimeError):
             op_np(y, -d)
-            
-        
-        op2_np = make_fixed_shift_lagrange_numpy(DynShiftBC.EXCEPTION, DynShiftBC.FLAT, length)
-        
+
+        op2_np = make_fixed_shift_lagrange_numpy(
+            DynShiftBC.EXCEPTION, DynShiftBC.FLAT, length
+        )
+
         s2_np = op2_np(y, -d)
         s2_ex = g(t + d * dt)
 
-- 
GitLab