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

internal renamings

parent fdb5361f
No related branches found
No related tags found
2 merge requests!842Annotated float scheme,!827Represent all flags by DictOfSeries
...@@ -69,29 +69,29 @@ class DmpScheme(MappingScheme): ...@@ -69,29 +69,29 @@ class DmpScheme(MappingScheme):
def __init__(self): def __init__(self):
super().__init__(forward=self._FORWARD, backward=self._BACKWARD) super().__init__(forward=self._FORWARD, backward=self._BACKWARD)
def toHistory(self, field_flags: pd.DataFrame): def toHistory(self, flags: pd.DataFrame):
""" """
Translate a single field of external ``Flags`` to a ``History`` Translate a single field of external ``Flags`` to a ``History``
""" """
field_history = History(field_flags.index) history = History(flags.index)
for (flag, cause, comment), values in field_flags.groupby(_QUALITY_LABELS): for (flag, cause, comment), values in flags.groupby(_QUALITY_LABELS):
try: try:
comment = json.loads(comment) comment = json.loads(comment)
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
comment = {"test": "unknown", "comment": ""} comment = {"test": "unknown", "comment": ""}
histcol = pd.Series(np.nan, index=field_flags.index) column = pd.Series(np.nan, index=flags.index)
histcol.loc[values.index] = self(flag) column.loc[values.index] = self(flag)
meta = { meta = {
"func": comment["test"], "func": comment["test"],
"kwargs": {"comment": comment["comment"], "cause": cause}, "kwargs": {"comment": comment["comment"], "cause": cause},
} }
field_history.append(histcol, meta=meta) history.append(column, meta=meta)
return field_history return history
def toInternal(self, df: pd.DataFrame) -> Flags: def toInternal(self, flags: pd.DataFrame | DictOfSeries) -> Flags:
""" """
Translate from 'external flags' to 'internal flags' Translate from 'external flags' to 'internal flags'
...@@ -105,12 +105,18 @@ class DmpScheme(MappingScheme): ...@@ -105,12 +105,18 @@ class DmpScheme(MappingScheme):
Flags object Flags object
""" """
self.validityCheck(df) self.validityCheck(flags)
data = {} data = {}
for field in df.columns.get_level_values(0).drop_duplicates(): if isinstance(flags, pd.DataFrame):
data[str(field)] = self.toHistory(df[field]) fields = flags.columns.get_level_values(0).drop_duplicates()
else:
fields = flags.columns
for field in fields:
data[str(field)] = self.toHistory(flags[field])
return Flags(data) return Flags(data)
...@@ -167,7 +173,7 @@ class DmpScheme(MappingScheme): ...@@ -167,7 +173,7 @@ class DmpScheme(MappingScheme):
return out return out
@classmethod @classmethod
def validityCheck(cls, dios: DictOfSeries) -> None: def validityCheck(cls, flags: pd.DataFrame | DictOfSeries) -> None:
""" """
Check wether the given causes and comments are valid. Check wether the given causes and comments are valid.
...@@ -176,7 +182,7 @@ class DmpScheme(MappingScheme): ...@@ -176,7 +182,7 @@ class DmpScheme(MappingScheme):
df : external flags df : external flags
""" """
for df in dios.values(): for df in flags.values():
if not df.columns.isin(_QUALITY_LABELS).all(axis=None): if not df.columns.isin(_QUALITY_LABELS).all(axis=None):
raise TypeError( raise TypeError(
......
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