From d710cb91f11bca35309b5a1d284c592ebe427131 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Sch=C3=A4fer?= <david.schaefer@ufz.de>
Date: Tue, 10 Jan 2023 11:26:30 +0100
Subject: [PATCH] Change the default limit value of the interpolation routines

---
 CHANGELOG.md                   |  1 +
 saqc/funcs/interpolation.py    | 14 ++++++--------
 saqc/lib/ts_operators.py       |  2 +-
 tests/funcs/test_resampling.py |  2 +-
 4 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 409b478b7..ffc9bd378 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
 - Remove all flag value restrictions from the default flagging scheme `FloatTranslator` 
 - Renamed `TranslationScheme.forward` to `TranslationScheme.toInternal` 
 - Renamed `TranslationScheme.backward` to `TranslationScheme.toExternal` 
+- Changed Default value of the parameter `limit` for `SaQC.interpolateIndex` and `SaQC.interpolateInvalid` to ``None`
 ### Removed
 ### Fixed
 
diff --git a/saqc/funcs/interpolation.py b/saqc/funcs/interpolation.py
index e25401429..e0907e261 100644
--- a/saqc/funcs/interpolation.py
+++ b/saqc/funcs/interpolation.py
@@ -143,7 +143,7 @@ class InterpolationMixin:
         field: str,
         method: _SUPPORTED_METHODS,
         order: int = 2,
-        limit: int = 2,
+        limit: int | None = None,
         downgrade: bool = False,
         flag: float = UNFLAGGED,
         **kwargs,
@@ -167,9 +167,8 @@ class InterpolationMixin:
             If there your selected interpolation method can be performed at different 'orders' - here you pass the desired
             order.
 
-        limit : int, default 2
-            Maximum number of consecutive 'nan' values allowed for a gap to be interpolated. This really restricts the
-            interpolation to chunks, containing not more than `limit` successive nan entries.
+        limit : int, optional
+            Maximum number of consecutive `nan` values to fill. Must be greater than 0.
 
         flag : float or None, default UNFLAGGED
             Flag that is set for interpolated values. If ``None``, no flags are set at all.
@@ -210,7 +209,7 @@ class InterpolationMixin:
         freq: str,
         method: _SUPPORTED_METHODS,
         order: int = 2,
-        limit: int = 2,
+        limit: int | None = None,
         downgrade: bool = False,
         **kwargs,
     ) -> "SaQC":
@@ -237,9 +236,8 @@ class InterpolationMixin:
             If there your selected interpolation method can be performed at different 'orders' - here you pass the desired
             order.
 
-        limit : int, default 2
-            Maximum number of consecutive 'nan' values allowed for a gap to be interpolated. This really restricts the
-            interpolation to chunks, containing not more than `limit` successive nan entries.
+        limit : int, optional
+            Maximum number of missing index values (with respect to `freq`) to fill. Must be greater than 0.
 
         downgrade : bool, default False
             If `True` and the interpolation can not be performed at current order, retry with a lower order.
diff --git a/saqc/lib/ts_operators.py b/saqc/lib/ts_operators.py
index 094875fcc..e63eb8b74 100644
--- a/saqc/lib/ts_operators.py
+++ b/saqc/lib/ts_operators.py
@@ -301,7 +301,7 @@ def interpolateNANs(
 
     :return:
     """
-    inter_limit = int(inter_limit)
+    inter_limit = int(inter_limit or len(data) + 1)
     data = pd.Series(data, copy=True)
     gap_mask = data.isna().rolling(inter_limit, min_periods=0).sum() != inter_limit
 
diff --git a/tests/funcs/test_resampling.py b/tests/funcs/test_resampling.py
index ebed5178e..c5dbd1570 100644
--- a/tests/funcs/test_resampling.py
+++ b/tests/funcs/test_resampling.py
@@ -124,7 +124,7 @@ def test_gridInterpolation(data, method, fill_history):
         res = qc.interpolate(
             field,
             freq,
-            order=10,
+            order=9,
             method=method,
             downcast_interpolation=True,
         )
-- 
GitLab