Skip to content
Snippets Groups Projects
Commit 84617a18 authored by Bert Palm's avatar Bert Palm 🎇
Browse files

simplified squeeze, as suggested by @schaefed

parent 8e72568d
No related branches found
No related tags found
1 merge request!218Flags
......@@ -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
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment