Skip to content
Snippets Groups Projects
Commit ffac6189 authored by David Schäfer's avatar David Schäfer
Browse files

Add option to not overwrite existing flags to concatFlags

parent 714aac54
No related branches found
No related tags found
4 merge requests!685Release 2.4,!684Release 2.4,!578Add option to not overwrite existing flags to concatFlags,!567Release 2.2.1
......@@ -9,6 +9,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
## Unreleased
[List of commits](https://git.ufz.de/rdm-software/saqc/-/compare/v2.2.1...develop)
### Added
- add option to not overwrite existing flags to `concatFlags`
### Changed
### Removed
### Fixed
......
......@@ -334,9 +334,10 @@ class ResamplingMixin:
"inverse_interpolation",
"match",
] = "match",
freq: Optional[str] = None,
drop: Optional[bool] = False,
squeeze: Optional[bool] = False,
freq: str | None = None,
drop: bool = False,
squeeze: bool = False,
overwrite: bool = True,
**kwargs,
) -> "SaQC":
"""
......@@ -394,6 +395,10 @@ class ResamplingMixin:
If set to `True`, the appended flags frame will be squeezed - resulting in function specific flags informations
getting lost.
overwrite: bool, default True
If set to True, the newly appended flags will overwrite exsiting flags. This might result in a loss of previous
flagging information.
Returns
-------
saqc.SaQC
......@@ -449,13 +454,19 @@ class ResamplingMixin:
raise ValueError(f"unknown method {method}")
history = self._flags.history[field].apply(dummy.index, func, func_kws)
if overwrite is False:
mask = _isflagged(self._flags[target], thresh=kwargs["dfilter"])
history.hist[mask] = np.nan
if squeeze:
history = history.squeeze(raw=True)
meta = {
"func": f"concatFlags({field})",
"args": (field, target),
"func": f"concatFlags",
"args": (field,),
"kwargs": {
"target": target,
"method": method,
"freq": freq,
"drop": drop,
......
......@@ -375,3 +375,55 @@ def test_harmSingleVarInterpolationShift(data, params, expected):
qc = qc.dropField(h_field)
assert qc.data[field].equals(pre_data[field])
assert qc.flags[field].equals(pre_flags[field])
def test_concatFlags():
index = pd.to_datetime(
[
"2020-01-01 00:00",
"2020-01-01 00:10",
"2020-01-01 00:30",
"2020-01-01 00:40",
"2020-01-01 01:00",
]
)
df = pd.DataFrame(
data={
"a": [
1,
2,
5,
4,
3,
]
},
index=index,
)
qc = SaQC(df)
qc = qc.flagRange(field="a", max=4)
# branch out to another variable
qc = qc.flagRange(field="a", target="b", max=3)
# bring the flags back again
qc_overwrite = qc.concatFlags("b", target="a", overwrite=True, squeeze=True)
hist_overwrite = qc_overwrite._flags.history["a"].hist.astype(float)
assert hist_overwrite[0].equals(
pd.Series([np.nan, np.nan, 255.0, np.nan, np.nan], index=index)
)
assert hist_overwrite[1].equals(
pd.Series([np.nan, np.nan, 255.0, 255.0, np.nan], index=index)
)
# bring the flags back again
qc_respect = qc.concatFlags("b", target="a", overwrite=False, squeeze=True)
hist_respect = qc_respect._flags.history["a"].hist.astype(float)
assert hist_respect[0].equals(
pd.Series([np.nan, np.nan, 255.0, np.nan, np.nan], index=index)
)
assert hist_respect[1].equals(
pd.Series([np.nan, np.nan, np.nan, 255.0, np.nan], index=index)
)
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