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

rewrite of _restoreFlags() in register.py which was needed because of a...

rewrite of _restoreFlags() in register.py which was needed because of a problem updating meta, which raised an index error when setting meta on an empty history
parent b7297e41
No related branches found
No related tags found
No related merge requests found
Pipeline #36980 passed with stage
in 2 minutes and 25 seconds
...@@ -39,7 +39,6 @@ class CallState: ...@@ -39,7 +39,6 @@ class CallState:
def processing(module: Optional[str] = None): def processing(module: Optional[str] = None):
# executed on module import # executed on module import
def inner(func): def inner(func):
func_name = func.__name__ func_name = func.__name__
...@@ -58,7 +57,6 @@ def processing(module: Optional[str] = None): ...@@ -58,7 +57,6 @@ def processing(module: Optional[str] = None):
def flagging(masking: MaskingStrT = "all", module: Optional[str] = None): def flagging(masking: MaskingStrT = "all", module: Optional[str] = None):
# executed on module import # executed on module import
def inner(func): def inner(func):
func_name = func.__name__ func_name = func.__name__
...@@ -324,65 +322,63 @@ def _restoreFlags(flags: Flags, old_state: CallState): ...@@ -324,65 +322,63 @@ def _restoreFlags(flags: Flags, old_state: CallState):
------- -------
Flags Flags
""" """
columns = flags.columns out = old_state.flags.copy()
meta = {
if old_state.masking == "all": "func": old_state.func_name,
pass "args": old_state.args,
"keywords": old_state.kwargs,
# The function processed a copy of the original flags and may or may not added some }
# columns. So we take only new history columns and define new flags with it, which new_columns = flags.columns.difference(old_state.flags.columns)
# are enriched with meta later
elif old_state.masking == "none": # masking == 'none'
flags = flags.copy(deep=False) # - no data was masked (no relevance here, but help understanding)
# - the saqc-function got a copy of the whole flags frame with all full histories
for c in flags.columns: # (but is not allowed to change them; we have -> @processing for this case)
# if a new field (aka. variable) was inserted, we take the full history and # - the saqc-function appended none or some columns to the each history
# no slicing is needed, which is the hidden else-case. #
if c in old_state.flags.columns: # masking == 'all'
l = len(old_state.flags.history[c].columns) # - all data was masked by flags (no relevance here, but help understanding)
flags.history[c] = _sliceHistory(flags.history[c], slice(l, None)) # - the saqc-function got a complete new flags frame, with empty Histories
# - the saqc-function appended none or some columns to the each history
# take field column and all possibly newly added columns #
# masking == 'field'
# - some data columns were masked by flags (no relevance here)
# - the saqc-function got a complete new flags frame, with empty Histories
# - the saqc-function appended none or some columns to the each history
# Note: actually the flags SHOULD have been cleared only at the field (as the
# masking-parameter implies) but the current implementation in `_prepareFlags`
# clear all columns. Nevertheless the following code only update the field (and new
# columns) and not all columns.
if old_state.masking == "none":
columns = flags.columns
elif old_state.masking == "all":
columns = flags.columns
elif old_state.masking == "field": elif old_state.masking == "field":
columns = columns.difference(old_state.flags.columns) columns = pd.Index([old_state.field])
columns = columns.append(pd.Index([old_state.field]))
else: else:
raise RuntimeError(old_state.masking) raise RuntimeError(old_state.masking)
out = old_state.flags.copy() for c in columns.union(new_columns):
# this implicitly squash the new flags history (RHS) to a single column, which than if c in new_columns:
# is appended to the old history (LHS). Thus because the new flags history possibly history = flags.history[c]
# consists of multiple columns, one for each time a series or scalar was passed to out.history[c] = History(index=history.index) # ensure existence
# the flags. # New columns was appended to the old history, but we want to have the new
for c in columns: # columns only. If old and new are the same (nothing was appended), we end up
# having a empty history, whats handled later correctly
elif old_state.masking == "none":
sl = slice(len(old_state.flags.history[c].columns), None)
history = _sliceHistory(flags.history[c], sl)
else:
history = flags.history[c]
squeezed = flags.history[c].max(raw=True)
# nothing to update
if history.empty or (squeezed == UNTOUCHED).all():
continue
h = flags.history[c] out.history[c] = out.history[c].append(squeezed, force=True, meta=meta)
hmax = h.max(raw=True)
# # handle empty case (i.e. test didn't set any flags, can happen on early returns),
# # to prevent a missing (empty) flags column
# if h.empty:
# out.history[c] = h.copy()
# continue
# # if nothing was touched we have no need to clutter the history
# if (hmax == UNTOUCHED).all():
# continue
out[c] = hmax
# we enrich the (already existing !) empty meta with some infos
history = out.history[c]
history.meta[-1].update(
{
"func": old_state.func_name,
"args": old_state.args,
"keywords": old_state.kwargs,
}
)
out.history[c] = history
return out return out
......
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