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

[FIX] pass actual flags into generic

parent b3a98afe
No related branches found
No related tags found
3 merge requests!271Static expansion of regular expressions,!269Several fixes,!260Follow-Up Translations
This commit is part of merge request !260. Comments created here will be created in the context of that merge request.
......@@ -210,13 +210,6 @@ def _getMaskingThresh(masking, kwargs, fname):
if not isinstance(thresh, (bool, float, int)):
raise TypeError(f"'to_mask' must be of type bool or float")
if masking == "none" and thresh not in (False, np.inf):
# TODO: fix warning reference to docu
warnings.warn(
f"the saqc-function {fname!r} ignores masking and therefore does not evaluate the passed "
f"'to_mask'-keyword. Please refer to the documentation: TODO"
)
if thresh is True: # masking ON
thresh = UNFLAGGED
......
......@@ -10,8 +10,9 @@ import pandas as pd
from dios import DictOfSeries
from saqc.constants import *
from saqc.core import register, initFlagsLike, Flags
from saqc.constants import GOOD, BAD, UNFLAGGED
from saqc.core.flags import initFlagsLike, Flags
from saqc.core.register import register, _maskData
from saqc.core.visitor import ENVIRONMENT
import operator as op
......@@ -84,13 +85,14 @@ def _execGeneric(
return func(*args)
@register(masking="all", module="generic")
@register(masking="none", module="generic")
def process(
data: DictOfSeries,
field: str,
flags: Flags,
func: Callable[[pd.Series], pd.Series],
nodata: float = np.nan,
to_mask: float = UNFLAGGED,
**kwargs,
) -> Tuple[DictOfSeries, Flags]:
"""
......@@ -142,18 +144,20 @@ def process(
>>> lambda temperature, uncertainty: np.round(temperature) * np.sqrt(uncertainty)
"""
data[field] = _execGeneric(flags, data, func, field, nodata).squeeze()
# we get the data unmaskes in order to also receive flags,
# so let's ge to the masking manually
data_masked, _ = _maskData(data, flags, data.columns, to_mask)
data[field] = _execGeneric(flags, data_masked, func, field, nodata).squeeze()
# TODO: the former comment wished to overwrite the column, but i'm not sure -- palmb
# see #GL177
if field in flags:
flags.drop(field)
flags[field] = initFlagsLike(data[field])[field]
return data, flags
@register(masking="all", module="generic")
@register(masking="none", module="generic")
def flag(
data: DictOfSeries,
field: str,
......@@ -161,6 +165,7 @@ def flag(
func: Callable[[pd.Series], pd.Series],
nodata: float = np.nan,
flag: float = BAD,
to_mask: float = UNFLAGGED,
**kwargs,
) -> Tuple[DictOfSeries, Flags]:
# TODO : fix docstring, check if all still works
......@@ -240,10 +245,11 @@ def flag(
>>> lambda level: np.sqrt(level) > 7
"""
# NOTE:
# The naming of the func parameter is pretty confusing
# as it actually holds the result of a generic expression
mask = _execGeneric(flags, data, func, field, nodata).squeeze()
# we get the data unmaskes in order to also receive flags,
# so let's ge to the masking manually
data_masked, _ = _maskData(data, flags, data.columns, to_mask)
mask = _execGeneric(flags, data_masked, func, field, nodata).squeeze()
if np.isscalar(mask):
raise TypeError(f"generic expression does not return an array")
if not np.issubdtype(mask.dtype, np.bool_):
......@@ -252,9 +258,6 @@ def flag(
if field not in flags.columns:
flags[field] = pd.Series(UNFLAGGED, index=mask.index, name=field)
# if flags.getFlags(field).empty:
# flags = flags.merge(
# flags.initFlags(
# data=pd.Series(name=field, index=mask.index, dtype=np.float64)))
flags[mask, field] = flag
return data, flags
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