From 12a648b0f2b95495c01495ea8a641e042f895224 Mon Sep 17 00:00:00 2001 From: Bert Palm <bert.palm@ufz.de> Date: Thu, 11 Feb 2021 18:35:41 +0100 Subject: [PATCH] refactored nr->pos; simplyfied/fixed _insert --- saqc/flagger/history.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/saqc/flagger/history.py b/saqc/flagger/history.py index 480afd634..79af5e0aa 100644 --- a/saqc/flagger/history.py +++ b/saqc/flagger/history.py @@ -127,7 +127,7 @@ class History: # but self.hist could have -> see pd.DataFrame.empty return self.mask.empty - def _insert(self, s: pd.Series, nr: int, force=False) -> History: + def _insert(self, s: pd.Series, pos: int, force=False) -> History: """ Insert data at an arbitrary position in the FH. @@ -138,11 +138,12 @@ class History: s : pd.Series the series to insert - nr : int + pos : int the position to insert force : bool, default False - if True the internal mask is updated accordingly + if True the internal mask is updated accordingly that the values overwrite + any earlier values in the FH. Returns ------- @@ -150,25 +151,16 @@ class History: """ # internal detail: # ensure continuous increasing columns - assert 0 <= nr <= len(self) + assert 0 <= pos <= len(self) - # we dont care about force on first insert - if self.empty: - assert nr == 0 - - self.mask[nr] = pd.Series(True, index=s.index, dtype=bool) - self.hist[nr] = s - return self + if pos == len(self): # append + self.mask[pos] = pd.Series(True, index=s.index, dtype=bool) if force: touched = np.isfinite(s) - self.mask.iloc[touched, :nr] = False - - # a column is appended - if nr == len(self): - self.mask[nr] = True + self.mask.iloc[touched, :pos] = False - self.hist[nr] = s + self.hist[pos] = s return self @@ -205,7 +197,7 @@ class History: if not self.empty and not s.index.equals(self.index): raise ValueError("Index must be equal to FH's index") - self._insert(value, nr=len(self), force=force) + self._insert(value, pos=len(self), force=force) return self def squeeze(self, n: int) -> History: -- GitLab