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

simplyfied register, according to @schaefed 's suggestions

parent e124ceaa
No related branches found
No related tags found
3 merge requests!271Static expansion of regular expressions,!260Follow-Up Translations,!237Flagger Translations
......@@ -102,15 +102,15 @@ def _preCall(func: callable, args: tuple, kwargs: dict, masking: MaskingStrT, fn
data, field, flagger, *args = args
ctrl = CallCtrl(func, data.copy(), field, flagger.copy(), args, kwargs, masking=masking, mthresh=mthresh)
# masking
columns = _getMaskingColumns(ctrl, ctrl.masking)
# handle data - masking
columns = _getMaskingColumns(data, field, masking)
data, mask = _maskData(data, flagger, columns, mthresh)
# store mask
ctrl.mask = mask
# flags
flagger = _prepareFlags(flagger, ctrl)
# handle flags - clearing
flagger = _prepareFlags(flagger, masking)
args = data, field, flagger, *args
return args, kwargs, ctrl
......@@ -144,18 +144,23 @@ def _postCall(result, ctrl: CallCtrl, fname: str) -> FuncReturnT:
return data, flagger
def _getMaskingColumns(ctrl: CallCtrl, masking: MaskingStrT):
def _getMaskingColumns(data: dios.DictOfSeries, field: str, masking: MaskingStrT):
"""
Returns
-------
columns: pd.Index
Data columns that need to be masked.
Raises
------
ValueError: if given masking literal is not supported
"""
if masking == 'all':
return ctrl.data.columns
return data.columns
if masking == 'none':
return pd.Index([])
if masking == 'field':
return pd.Index([ctrl.field])
return pd.Index([field])
raise ValueError(f"wrong use of `register(masking={ctrl.masking})`")
......@@ -243,12 +248,12 @@ def _getMask(flags: Union[np.array, pd.Series], thresh: float) -> Union[np.array
return flags >= thresh
def _prepareFlags(flagger: Flagger, ctrl: CallCtrl) -> Flagger:
def _prepareFlags(flagger: Flagger, masking) -> Flagger:
"""
Clear flags before each call.
"""
# either the index or the columns itself changed
if ctrl.masking == 'none':
# Either the index or the columns itself changed
if masking == 'none':
return flagger
return initFlagsLike(flagger, initial_value=UNTOUCHED)
......@@ -267,6 +272,9 @@ def _restoreFlags(flagger: Flagger, ctrl: CallCtrl):
columns = columns.append(pd.Index([ctrl.field]))
for c in columns:
# this implicitly squash the new-flagger history (RHS) to a single column, which than is appended to
# the old history (LHS). The new-flagger history possibly consist of multiple columns, one for each
# time flags was set to the flagger.
result[c] = flagger[c]
return result
......
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