From 84617a18f5b53e88a70dd87685dad83a741887db Mon Sep 17 00:00:00 2001
From: Bert Palm <bert.palm@ufz.de>
Date: Fri, 12 Feb 2021 00:34:20 +0100
Subject: [PATCH] simplified squeeze, as suggested by @schaefed

---
 saqc/flagger/history.py      | 35 ++++++++++++++---------------------
 test/flagger/test_history.py |  2 +-
 2 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/saqc/flagger/history.py b/saqc/flagger/history.py
index 0db2c218e..9eeb9aa9f 100644
--- a/saqc/flagger/history.py
+++ b/saqc/flagger/history.py
@@ -230,27 +230,20 @@ class History:
         if n > len(self):
             raise ValueError(f"'n={n}' cannot be greater than columns in the FH")
 
-        # shortcut
-        if len(self) == n:
-            s = self.max()
-            self.hist = pd.DataFrame()
-            self.mask = pd.DataFrame()
-
-        else:
-            # calc the squeezed series.
-            # we dont have to care about any forced series
-            # because anytime force was given, the False's in
-            # the mask were propagated back over the whole FH
-            mask = self.mask.iloc[:, -n:]
-            hist = self.hist.iloc[:, -n:]
-            s = hist[mask].max(axis=1)
-
-            # slice self down
-            # this may leave us in an unstable state, because
-            # the last column may not is entirely True, but
-            # the following append, will fix this
-            self.hist = self.hist.iloc[:, :-n]
-            self.mask = self.mask.iloc[:, :-n]
+        # calc the squeezed series.
+        # we dont have to care about any forced series
+        # because anytime force was given, the False's in
+        # the mask were propagated back over the whole FH
+        mask = self.mask.iloc[:, -n:]
+        hist = self.hist.iloc[:, -n:]
+        s = hist[mask].max(axis=1)
+
+        # slice self down
+        # this may leave us in an unstable state, because
+        # the last column maybe is not entirely True, but
+        # the following append, will fix this
+        self.hist = self.hist.iloc[:, :-n]
+        self.mask = self.mask.iloc[:, :-n]
 
         self.append(s)
         return self
diff --git a/test/flagger/test_history.py b/test/flagger/test_history.py
index f4c068ef7..59261b5f5 100644
--- a/test/flagger/test_history.py
+++ b/test/flagger/test_history.py
@@ -234,7 +234,7 @@ def test_squeeze():
 
     # checks
 
-    for n in range(len(orig)):
+    for n in range(len(orig) + 1):
         hist = orig.copy()
         hist.squeeze(n)
 
-- 
GitLab