From a13af8b83d74d2181a1e938d350ac82b8d75c4d3 Mon Sep 17 00:00:00 2001
From: Bert Palm <bert.palm@ufz.de>
Date: Tue, 2 Mar 2021 14:35:38 +0100
Subject: [PATCH] fixed breaks.py

---
 saqc/funcs/breaks.py | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/saqc/funcs/breaks.py b/saqc/funcs/breaks.py
index 7f21609be..107c3c3e7 100644
--- a/saqc/funcs/breaks.py
+++ b/saqc/funcs/breaks.py
@@ -12,6 +12,7 @@ from typing import Tuple
 
 import numpy as np
 import pandas as pd
+import pandas.tseries.frequencies
 
 from dios import DictOfSeries
 
@@ -27,7 +28,7 @@ def flagMissing(
         data: DictOfSeries,
         field: ColumnName,
         flagger: Flagger,
-        nodata: float=np.nan,
+        nodata: float = np.nan,
         **kwargs
 ) -> Tuple[DictOfSeries, Flagger]:
     """
@@ -59,7 +60,7 @@ def flagMissing(
     else:
         mask = datacol == nodata
 
-    flagger = flagger.setFlags(field, loc=mask, **kwargs)
+    flagger[mask, field] = kwargs['flag']
     return data, flagger
 
 
@@ -76,7 +77,7 @@ def flagIsolated(
     The function flags arbitrary large groups of values, if they are surrounded by sufficiently
     large data gaps.
 
-    A gap is a timespan containing either no data or invalid (usually `nan`) and flagged data only.
+    A gap is a timespan containing either no data or data invalid only (usually `nan`) .
 
     Parameters
     ----------
@@ -85,7 +86,7 @@ def flagIsolated(
     field : str
         The fieldname of the column, holding the data-to-be-flagged.
     flagger : saqc.flagger.Flagger
-        A flagger object, holding flags and additional informations related to `data`.
+        A flagger object
     gap_window : str
         The minimum size of the gap before and after a group of valid values, making this group considered an
         isolated group. See condition (2) and (3)
@@ -98,8 +99,7 @@ def flagIsolated(
     data : dios.DictOfSeries
         A dictionary of pandas.Series, holding all the data.
     flagger : saqc.flagger.Flagger
-        The flagger object, holding flags and additional Informations related to `data`.
-        Flags values may have changed relatively to the flagger input.
+        The flagger object, holding flags and additional information related to `data`.
 
     Notes
     -----
@@ -107,8 +107,8 @@ def flagIsolated(
     is considered to be isolated, if:
 
     1. :math:`t_{k+1} - t_n <` `group_window`
-    2. None of the :math:`x_j` with :math:`0 < t_k - t_j <` `gap_window`, is valid or unflagged (preceeding gap).
-    3. None of the :math:`x_j` with :math:`0 < t_j - t_(k+n) <` `gap_window`, is valid or unflagged (succeding gap).
+    2. None of the :math:`x_j` with :math:`0 < t_k - t_j <` `gap_window`, is valid (preceeding gap).
+    3. None of the :math:`x_j` with :math:`0 < t_j - t_(k+n) <` `gap_window`, is valid (succeding gap).
 
     See Also
     --------
@@ -118,10 +118,9 @@ def flagIsolated(
     gap_window = pd.tseries.frequencies.to_offset(gap_window)
     group_window = pd.tseries.frequencies.to_offset(group_window)
 
-    col = data[field].mask(flagger.isFlagged(field))
-    mask = col.isnull()
+    mask = data[field].isna()
 
-    flags = pd.Series(data=0, index=col.index, dtype=bool)
+    flags = pd.Series(data=0, index=mask.index, dtype=bool)
     for srs in groupConsecutives(mask):
         if np.all(~srs):
             start = srs.index[0]
@@ -133,8 +132,7 @@ def flagIsolated(
                     if right.all():
                         flags[start:stop] = True
 
-    flagger = flagger.setFlags(field, flags, **kwargs)
-
+    flagger[mask, field] = kwargs['flag']
     return data, flagger
 
 
@@ -145,7 +143,7 @@ def flagJumps(
         flagger: Flagger,
         thresh: float,
         winsz: FreqString,
-        min_periods: IntegerWindow=1,
+        min_periods: IntegerWindow = 1,
         **kwargs
 ) -> Tuple[DictOfSeries, Flagger]:
     """
-- 
GitLab