Skip to content
Snippets Groups Projects

Follow-Up Translations

Merged David Schäfer requested to merge translations into develop
Compare and Show latest version
5 files
+ 73
18
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -60,7 +60,22 @@ class DmpTranslator(Translator):
----
Could (and maybe should) be implemented as a method of `CallGraph`
"""
return [SaQCFunction(name="")] + [f for l, f in call_stack if l.field == field]
out = [SaQCFunction(name="")]
for sel, func in call_stack:
if sel.field == field:
out.append(func)
# NOTE:
# This is an intermediary hack, to work around
# the problem, that field names are mutable and
# used as an mapping between `History` and
# `call_stack`. There are better ideas, to solve
# this (i.e. global function pointer) but for the
# moment this has to do the trick
if func.name == "tools.rename":
field = func.keywords.get("new_name") or func.args[3]
return out
def forward(self, flags: pd.DataFrame) -> Tuple[Flags, MaterializedGraph]:
"""
@@ -144,6 +159,11 @@ class DmpTranslator(Translator):
flag_call_history = self._getFieldFunctions(field, call_graph)
flag_pos = flags.history[field].idxmax()
comments, causes = [], []
# NOTE:
# Strangely enough, this loop withstood all my efforts
# to speed it up through vectorization - the simple
# loop always outperformed even careful `pd.DataFrame.apply`
# versions. The latest try is left as a comment below.
for p in flag_pos:
func = flag_call_history[p]
cause = func.keywords.get("cause", self.ARGUMENTS["cause"])
@@ -165,3 +185,26 @@ class DmpTranslator(Translator):
}
out[field] = pd.DataFrame(var_flags)
return pd.concat(out, axis="columns")
# for field in tflags.columns:
# call_history = []
# for func in self._getFieldFunctions(field, call_graph):
# func_info = {
# "cause": func.keywords.get("cause", self.ARGUMENTS["comment"]),
# "comment": json.dumps({
# "test": func.name,
# "comment": func.keywords.get("comment", self.ARGUMENTS["comment"]),
# })
# }
# call_history.append(func_info)
# functions = pd.DataFrame(call_history)
# flag_pos = flags.history[field].idxmax()
# var_flags = {
# "quality_flag": tflags[field].reset_index(drop=True),
# "quality_comment": functions.loc[flag_pos, "comment"].reset_index(drop=True),
# "quality_cause": functions.loc[flag_pos, "cause"].reset_index(drop=True),
# }
# out[field] = pd.DataFrame(var_flags, index=flag_pos.index)
# return pd.concat(out, axis="columns")
Loading