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

undo changes to FloatScheme

parent 470393e6
No related branches found
No related tags found
1 merge request!842Annotated float scheme
Pipeline #206291 failed with stages
in 3 minutes and 48 seconds
......@@ -11,27 +11,39 @@ from __future__ import annotations
import numpy as np
import pandas as pd
from saqc.constants import UNFLAGGED
from saqc.constants import FILTER_ALL, UNFLAGGED
from saqc.core.flags import Flags
from saqc.core.frame import DictOfSeries
from saqc.core.history import History
from saqc.core.translation.basescheme import MappingScheme
from saqc.core.translation.basescheme import TranslationScheme
class FloatScheme(MappingScheme):
class FloatScheme(TranslationScheme):
"""
Acts as the default Translator, provides a changeable subset of the
internal float flags
"""
_MAP = {
np.nan: np.nan,
-np.inf: -np.inf,
**{k: k for k in np.arange(0, 256, dtype=float)},
}
DFILTER_DEFAULT: float = FILTER_ALL
def __init__(self):
super().__init__(forward=self._MAP, backward=self._MAP)
def __call__(self, flag: float | int) -> float:
try:
return float(flag)
except (TypeError, ValueError, OverflowError):
raise ValueError(f"invalid flag, expected a numerical value, got: {flag}")
def toInternal(self, flags: pd.DataFrame | DictOfSeries) -> Flags:
try:
return Flags(flags.astype(float))
except (TypeError, ValueError, OverflowError):
raise ValueError(
f"invalid flag(s), expected a collection of numerical values, got: {flags}"
)
def toExternal(self, flags: Flags, attrs: dict | None = None) -> DictOfSeries:
out = DictOfSeries(flags)
out.attrs = attrs or {}
return out
class AnnotatedFloatScheme(FloatScheme):
......
......@@ -13,8 +13,8 @@ import numpy as np
import pandas as pd
import pytest
from saqc import BAD, DOUBTFUL, FILTER_NONE, UNFLAGGED, SaQC
from saqc.core import Flags
from saqc.constants import BAD, DOUBTFUL, FILTER_NONE, UNFLAGGED
from saqc.core import Flags, SaQC
from saqc.core.translation import DmpScheme, MappingScheme, PositionalScheme
from saqc.core.translation.floatscheme import AnnotatedFloatScheme
from tests.common import initData
......@@ -291,8 +291,6 @@ def test_annotatedFloatScheme():
)
flags = saqc.flags
qfunc = pd.DataFrame({k: v["func"] for k, v in flags.items()})
assert flags[col]["flag"].isin({DOUBTFUL, BAD, UNFLAGGED}).all(axis=None)
assert flags[col]["func"].isin({"", "setFlags", "flagRange"}).all(axis=None)
......
......@@ -48,24 +48,24 @@ N = np.nan
([B, U, U, U, U], [N, N, N, N, N], {"window": "10D", "method": "bfill"}),
# playing with dfilter
(
[2, B, 0, 0, 0],
[1, B, -1, -1, -1],
[N, N, B, B, N],
{"window": 2, "method": "ffill", "dfilter": 1},
{"window": 2, "method": "ffill", "dfilter": 0},
),
(
[0, 0, 0, B, 2],
[-1, -1, -1, B, 1],
[N, B, B, N, N],
{"window": 2, "method": "bfill", "dfilter": 1},
{"window": 2, "method": "bfill", "dfilter": 0},
),
(
[B, 2, 0, 2, 2],
[B, 1, -1, 1, 1],
[N, N, B, N, N],
{"window": "2D", "method": "ffill", "dfilter": 1},
{"window": "2D", "method": "ffill", "dfilter": 0},
),
(
[B, 2, 2, 0, 2],
[B, 1, 1, -1, 1],
[N, N, N, B, N],
{"window": "2D", "method": "bfill", "dfilter": 1},
{"window": "2D", "method": "bfill", "dfilter": 0},
),
],
)
......
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