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

refactored nr->pos; simplyfied/fixed _insert

parent e83023c1
No related branches found
No related tags found
1 merge request!218Flags
...@@ -127,7 +127,7 @@ class History: ...@@ -127,7 +127,7 @@ class History:
# but self.hist could have -> see pd.DataFrame.empty # but self.hist could have -> see pd.DataFrame.empty
return self.mask.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. Insert data at an arbitrary position in the FH.
...@@ -138,11 +138,12 @@ class History: ...@@ -138,11 +138,12 @@ class History:
s : pd.Series s : pd.Series
the series to insert the series to insert
nr : int pos : int
the position to insert the position to insert
force : bool, default False 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 Returns
------- -------
...@@ -150,25 +151,16 @@ class History: ...@@ -150,25 +151,16 @@ class History:
""" """
# internal detail: # internal detail:
# ensure continuous increasing columns # ensure continuous increasing columns
assert 0 <= nr <= len(self) assert 0 <= pos <= len(self)
# we dont care about force on first insert if pos == len(self): # append
if self.empty: self.mask[pos] = pd.Series(True, index=s.index, dtype=bool)
assert nr == 0
self.mask[nr] = pd.Series(True, index=s.index, dtype=bool)
self.hist[nr] = s
return self
if force: if force:
touched = np.isfinite(s) touched = np.isfinite(s)
self.mask.iloc[touched, :nr] = False self.mask.iloc[touched, :pos] = False
# a column is appended
if nr == len(self):
self.mask[nr] = True
self.hist[nr] = s self.hist[pos] = s
return self return self
...@@ -205,7 +197,7 @@ class History: ...@@ -205,7 +197,7 @@ class History:
if not self.empty and not s.index.equals(self.index): if not self.empty and not s.index.equals(self.index):
raise ValueError("Index must be equal to FH's 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 return self
def squeeze(self, n: int) -> History: def squeeze(self, n: int) -> History:
......
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