diff --git a/saqc/funcs/rolling.py b/saqc/funcs/rolling.py index a98be5b087d32a65e4843286c128b27b78ca5b23..5988ab6072c9ba6891dc16d254686c8c3dad717d 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,