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

a few simplifications

parent 554cf654
No related branches found
No related tags found
No related merge requests found
......@@ -46,12 +46,6 @@ def initFunctionNamespace(nodata, flagger):
}
def setKey(d, key, value):
out = copy.copy(d)
out[key] = value
return out
def _raiseNameError(name, expr):
raise NameError(
"name '{:}' is not definied (failing expression: '{:}')"
......@@ -63,8 +57,6 @@ def evalExpression(expr: str, flagger: BaseFlagger,
field: str, nodata: Number = np.nan,
**namespace: dict) -> np.ndarray:
# type: (...) -> np.ndarray[bool]
def _eval(node, namespace):
# type: (ast.Node, dict) -> None
# the namespace dictionary should provide the data frame for the device
......@@ -97,8 +89,7 @@ def evalExpression(expr: str, flagger: BaseFlagger,
except KeyError:
_raiseNameError(node.func.id, expr)
namespace = setKey(namespace, "target", target)
args = [_eval(n, namespace) for n in node.args]
args = [_eval(n, {**namespace, **{"target": target}}) for n in node.args]
return func(*args)
elif isinstance(node, ast.Name): # <variable>
......
......@@ -29,9 +29,7 @@ def test_accesors():
def test_isFlagged():
flagger = BaseFlagger([-1, 0, 1])
data = initData(cols=1).iloc[:50]
flags = pd.DataFrame(index=data.index,
columns=data.columns,
data=flagger.UNFLAGGED)
flags = flagger.initFlags(data)
flags.iloc[:10] = flagger.BAD
flags.iloc[10:20] = flagger.GOOD
......
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