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

[FIX] flagGeneric: don't fail on empty data

parent a2acd418
No related branches found
No related tags found
7 merge requests!685Release 2.4,!684Release 2.4,!567Release 2.2.1,!566Release 2.2,!501Release 2.1,!400Relase 2.0.1,!389[FIX] flagGeneric: don't fail on empty data
Pipeline #55212 passed with stage
in 1 minute and 40 seconds
......@@ -267,7 +267,7 @@ def flagGeneric(
f"the generic function returned {len(result.columns)} field(s), but only {len(targets)} target(s) were given"
)
if not (result.dtypes == bool).all():
if not result.empty and not (result.dtypes == bool).all():
raise TypeError(f"generic expression does not return a boolean array")
meta = {
......
......@@ -8,6 +8,7 @@ from dios.dios.dios import DictOfSeries
from saqc.constants import BAD, UNFLAGGED, FILTER_ALL
from saqc.core.flags import Flags
from saqc import SaQC
from saqc.core.register import _isflagged
from saqc.lib.tools import toSequence
from tests.common import initData
......@@ -18,6 +19,19 @@ def data():
return initData()
def test_emptyData():
# test that things do not break with empty data sets
saqc = SaQC(data=pd.DataFrame({"x": [], "y": []}))
saqc.flagGeneric("x", func=lambda x: x < 0)
assert saqc.data.empty
assert saqc.flags.empty
saqc = saqc.processGeneric(field="x", target="y", func=lambda x: x + 2)
assert saqc.data.empty
assert saqc.flags.empty
def test_writeTargetFlagGeneric(data):
params = [
(["tmp"], lambda x, y: pd.Series(True, index=x.index.union(y.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