Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
dates
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Feb 18, 2024
1 parent ca4e947 commit 3e31b9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ecml_tools/create/functions/actions/mars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ecml_tools.create.utils import to_datetime_list

DEBUG = True
DEBUG = False


def to_list(x):
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ecml_tools/create/functions/actions/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
19 changes: 11 additions & 8 deletions ecml_tools/create/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 3e31b9c

Please sign in to comment.