From bac2aaeccbaa709b8f6a337fd38aa55ec5c7a913 Mon Sep 17 00:00:00 2001 From: Bert Palm <bert.palm@ufz.de> Date: Thu, 3 Dec 2020 16:35:05 +0100 Subject: [PATCH] adjusted saqc calls to customRoller --- saqc/funcs/constants_detection.py | 2 +- saqc/funcs/modelling.py | 12 +++++------- saqc/lib/rolling.py | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/saqc/funcs/constants_detection.py b/saqc/funcs/constants_detection.py index c8382ab5c..d40205690 100644 --- a/saqc/funcs/constants_detection.py +++ b/saqc/funcs/constants_detection.py @@ -50,7 +50,7 @@ def constants_flagBasic(data, field, flagger, thresh, window, **kwargs): # min_periods=2 ensures that at least two non-nan values are present # in each window and also min() == max() == d[i] is not possible. - kws = dict(window=window, min_periods=2) + kws = dict(window=window, min_periods=2, expand=False) # find all consecutive constant values in one direction... r = customRoller(d, **kws) diff --git a/saqc/funcs/modelling.py b/saqc/funcs/modelling.py index 704a8b52b..59f169c52 100644 --- a/saqc/funcs/modelling.py +++ b/saqc/funcs/modelling.py @@ -512,13 +512,11 @@ def modelling_changePointCluster(data, field, flagger, stat_func, thresh_func, b if reduce_window is None: reduce_window = f"{int(pd.Timedelta(bwd_window).total_seconds() + pd.Timedelta(fwd_window).total_seconds())}s" - # native pandas.rolling also fails - data_ser.rolling(window=bwd_window, min_periods=min_periods_bwd, closed=closed) - roller = customRoller(data_ser, window=bwd_window, min_periods=min_periods_bwd, closed=closed) - bwd_start, bwd_end = roller.window.get_window_bounds() + roller = customRoller(data_ser, window=bwd_window) + bwd_start, bwd_end = roller.window.get_window_bounds(len(data_ser), min_periods=min_periods_bwd, closed=closed) - roller = customRoller(data_ser, window=fwd_window, min_periods=min_periods_fwd, closed=closed, forward=True) - fwd_start, fwd_end = roller.window.get_window_bounds() + roller = customRoller(data_ser, window=fwd_window, forward=True) + fwd_start, fwd_end = roller.window.get_window_bounds(len(data_ser), min_periods=min_periods_fwd, closed=closed) min_mask = ~((fwd_end - fwd_start <= min_periods_fwd) | (bwd_end - bwd_start <= min_periods_bwd)) fwd_end = fwd_end[min_mask] @@ -560,7 +558,7 @@ def modelling_changePointCluster(data, field, flagger, stat_func, thresh_func, b detected = pd.Series(True, index=det_index) if reduce_window is not False: l = detected.shape[0] - roller = customRoller(detected, window=reduce_window, min_periods=1, closed='both', center=True) + roller = customRoller(detected, window=reduce_window) start, end = roller.window.get_window_bounds(num_values=l, min_periods=1, closed='both', center=True) detected = _reduceCPCluster(stat_arr[result_arr], thresh_arr[result_arr], start, end, reduce_func, l) diff --git a/saqc/lib/rolling.py b/saqc/lib/rolling.py index 49e7f4316..323cf1789 100644 --- a/saqc/lib/rolling.py +++ b/saqc/lib/rolling.py @@ -324,9 +324,9 @@ def customRoller(obj, window, min_periods=None, # aka minimum non-nan values Notes ----- If for some reason the start and end numeric indices of the window are needed, one can call - `start, end = customRoller(obj, ...).window.get_window_bounds()`, which return two arrays, - holding the start and end indices. Any passed (allowed) parameter to `get_window_bounds()` is - ignored and the arguments that was passed to `customRoller()` beforehand will be used instead. + `start, end = customRoller(obj, window).window.get_window_bounds(num_values, min_periods)`, + which return two np.arrays, that are holding the start and end indices. Fill at least all + parameter which are shown in the example. See Also -------- -- GitLab