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

added generic isflagged

parent fe66a4b1
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,8 @@ from numbers import Number
import numpy as np
import pandas as pd
from flagger import BaseFlagger
# supported operators
OPERATORS = {
......@@ -24,7 +26,6 @@ OPERATORS = {
}
def initFunctionNamespace(nodata):
def initFunctionNamespace(nodata, flagger):
return {
"abs": (abs, "data"),
......@@ -34,7 +35,9 @@ def initFunctionNamespace(nodata, flagger):
"sum": (np.sum, "data"),
"std": (np.std, "data"),
"len": (len, "data"),
"ismissing": (lambda d: ((d == nodata) | pd.isnull(d)), "data")}
"ismissing": (lambda d: ((d == nodata) | pd.isnull(d)), "data"),
"isflagged": (flagger.isFlagged, "flags")
}
def setKey(d, key, value):
......
......@@ -34,5 +34,25 @@ def test_ismissing():
assert (pd.isnull(fdata) | (fdata == nodata)).all()
def test_isflagged():
flagger = SimpleFlagger()
data = initData()
flags = flagger.emptyFlags(data, 0)
var1, var2, *_ = data.columns
flags.iloc[::2, 0] = flagger.setFlag(flags.iloc[::2, 0])
idx = evalCondition(
"isflagged({:})".format(var1),
flagger,
data, flags,
var2)
flagged = flagger.isFlagged(flags[var1])
assert (flagged == idx).all
if __name__ == "__main__":
test_ismissing()
test_isflagged()
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