From da54613c93b58309306a27f38e92033382566382 Mon Sep 17 00:00:00 2001
From: luenensc <peter.luenenschloss@ufz.de>
Date: Tue, 16 Apr 2024 20:32:04 +0200
Subject: [PATCH] exposed target in rolling func

---
 saqc/funcs/rolling.py | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/saqc/funcs/rolling.py b/saqc/funcs/rolling.py
index a98be5b08..5988ab607 100644
--- a/saqc/funcs/rolling.py
+++ b/saqc/funcs/rolling.py
@@ -34,6 +34,7 @@ class RollingMixin:
         self: "SaQC",
         field: str,
         window: str | int,
+        target: str = None,
         func: Callable[[pd.Series], np.ndarray] | str = "mean",
         min_periods: int = 0,
         center: bool = True,
@@ -55,6 +56,11 @@ class RollingMixin:
             sampled timeseries, the period number will be casted down to an odd number if
             ``center=True``.
 
+        target :
+            Field to write the result of the rolling calculation to. Will be generated if not existant.
+            If not given, `field` will be overwritten with the calculations result.
+            If multiple fields are given, `target` must be assigned.
+
         func : default mean
             Function to roll with.
 
@@ -66,9 +72,9 @@ class RollingMixin:
         """
         # HINT: checking in  _roll
         if len(field) == 1:
-            if "target" in kwargs:
-                self = self.copyField(field[0], target=kwargs["target"])
-                field = kwargs["target"]
+            if target:
+                self = self.copyField(field[0], target=target)
+                field = target
 
             self._data, self._flags = _roll(
                 data=self._data,
@@ -81,23 +87,23 @@ class RollingMixin:
                 **kwargs,
             )
         else:
-            if not "target" in kwargs:
+            if not target:
                 raise ValueError(
                     "Target has to be assigned for cross statistics calculations."
                 )
-            for t in kwargs["target"]:
-                if t not in self._data.columns:
-                    self[t] = saqc.SaQC(
-                        pd.Series(
-                            np.nan, index=self.data[field].to_pandas().index, name=t
-                        )
+
+            if target not in self._data.columns:
+                self[target] = saqc.SaQC(
+                    pd.Series(
+                        np.nan, index=self.data[field].to_pandas().index, name=target
                     )
+                )
 
             self._data, self._flags = _hroll(
                 data=self._data,
                 field=field,
                 flags=self._flags,
-                target=kwargs["target"],
+                target=target,
                 window=window,
                 func=func,
                 min_periods=min_periods,
-- 
GitLab