propagate flags too restrictive
- It proofs a little unwieldy and contraintuitive that
propagateFlagsshould only work on the last columns flags. (also strange things happen on data that results fromalignapplication)
- could be lifted with an additional keyword allowing for targeting columns with e certain
label
- The implementation only allows for application with regularily sampled data.
- can easily be lifted with wrapping
pandas.reindex
Added the following advanced propagateFlags implementation for a use case and see no reason not to add that to the stat would add it to base library.
def _propagateTrue(flagser,
method,
tolerance):
"""
Helper function.
Propagates True entries in boolean Series by `tolerance` in direction indicated by `method`
"""
f = flagser[flagser]
return f.reindex(flagser.index, method=method, tolerance=tolerance, fill_value=False)
@flagging()
def propagateFlagged(qc: saqc.SaQC,
field: str | list[str],
method: Literal["ffill", "bfill"],
window: str,
prop_label: str = None,
**kwargs):
"""
qc: SaQC object
method: direction of propagation ("ffill": forward, "bfill": backward)
window: extent of flags propagation (given as Offset String)
prop_label: label of flag to propagate (if none is given, the result from isflagged(field) will be propagated instead)
"""
prop_func = functools.partial(_propagateTrue, method=method, tolerance=window)
f = lambda x: prop_func(isflagged(x, prop_label))
return qc.flagGeneric(field, func=f, **kwargs)