From 3e31b9c1c50a8c0b38c1e1cd2e0b7dbe248accb2 Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Sun, 18 Feb 2024 14:22:51 +0000 Subject: [PATCH] dates --- ecml_tools/create/functions/actions/mars.py | 4 ++-- ecml_tools/create/functions/actions/source.py | 2 +- ecml_tools/create/input.py | 19 +++++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ecml_tools/create/functions/actions/mars.py b/ecml_tools/create/functions/actions/mars.py index 962abe3..525d9ee 100644 --- a/ecml_tools/create/functions/actions/mars.py +++ b/ecml_tools/create/functions/actions/mars.py @@ -14,7 +14,7 @@ from ecml_tools.create.utils import to_datetime_list -DEBUG = True +DEBUG = False def to_list(x): @@ -80,7 +80,7 @@ def mars(context, dates, *requests, **kwargs): for r in requests: r = {k: v for k, v in r.items() if v != ("-",)} if DEBUG: - print(f"✅ load_source(mars, {r}") + context.trace("✅", f"load_source(mars, {r}") ds = ds + load_source("mars", **r) return ds diff --git a/ecml_tools/create/functions/actions/source.py b/ecml_tools/create/functions/actions/source.py index f2723e5..13f00b5 100644 --- a/ecml_tools/create/functions/actions/source.py +++ b/ecml_tools/create/functions/actions/source.py @@ -15,7 +15,7 @@ def source(context, dates, **kwargs): name = kwargs.pop("name") - print(f"✅ load_source({name}, {dates}, {kwargs}") + context.trace("✅", f"load_source({name}, {dates}, {kwargs}") if kwargs["date"] == "$from_dates": kwargs["date"] = list({d.strftime("%Y%m%d") for d in dates}) if kwargs["time"] == "$from_dates": diff --git a/ecml_tools/create/input.py b/ecml_tools/create/input.py index 4f2332c..5333aff 100644 --- a/ecml_tools/create/input.py +++ b/ecml_tools/create/input.py @@ -353,16 +353,14 @@ class Result(HasCoordsMixin): def __init__(self, context, action_path, dates): assert isinstance(context, Context), type(context) - - assert action_path is None or isinstance(action_path, list), action_path - action_path = tuple(action_path or []) + assert isinstance(action_path, list), action_path self.context = context self._coords = Coords(self) self._dates = dates self.action_path = action_path - if action_path is not None: - context.register_reference(action_path, self) + + context.register_reference(action_path, self) @property @trace_datasource @@ -425,6 +423,9 @@ def _trace_datasource(self, *args, **kwargs): class EmptyResult(Result): empty = True + def __init__(self, context, action_path, dates): + super().__init__(context, action_path + ["empty"], dates) + @cached_property @trace_datasource def datasource(self): @@ -484,7 +485,7 @@ def __init__(self, context, action_path, dates, results, **kwargs): @check_references @trace_datasource def datasource(self): - ds = EmptyResult(self.context, None, self._dates).datasource + ds = EmptyResult(self.context, self.action_path, self._dates).datasource for i in self.results: ds += i.datasource assert_is_fieldset(ds), i @@ -715,7 +716,7 @@ def __init__(self, context, action_path, **kwargs): subconfig[k] = v self._dates = build_groups(datesconfig) - self.content = action_factory(subconfig, context) + self.content = action_factory(subconfig, context, self.action_path + ["dates"]) @trace_select def select(self, dates): @@ -846,7 +847,9 @@ def register_reference(self, action_path, obj): action_path = tuple(action_path) trace("📚", step(action_path), "register", type(obj)) if action_path in self.references: - raise ValueError(f"Duplicate reference {action_path}") + raise ValueError( + f"Duplicate reference [{action_path}] {obj} {self.references[action_path]}" + ) self.references[action_path] = obj def find_reference(self, action_path):