From 28547f7a0ecfb70cd0ec304c810caea446878092 Mon Sep 17 00:00:00 2001 From: Florian Pinault Date: Mon, 19 Feb 2024 16:20:27 +0000 Subject: [PATCH] fix concat --- ecml_tools/create/__init__.py | 1 - ecml_tools/create/input.py | 22 ++++++++++++++-------- ecml_tools/create/loaders.py | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ecml_tools/create/__init__.py b/ecml_tools/create/__init__.py index 6d0c72e..0c22af9 100644 --- a/ecml_tools/create/__init__.py +++ b/ecml_tools/create/__init__.py @@ -109,7 +109,6 @@ def cleanup(self): ) loader.run() - def patch(self, **kwargs): from .patch import apply_patch diff --git a/ecml_tools/create/input.py b/ecml_tools/create/input.py index 5333aff..7c622f6 100644 --- a/ecml_tools/create/input.py +++ b/ecml_tools/create/input.py @@ -200,6 +200,7 @@ def grid_points(self): def dates(self): if self._dates is None: raise ValueError(f"No dates for {self}") + assert hasattr(self._dates, "values"), (type(self), self._dates) return self._dates.values @cached_property @@ -523,15 +524,15 @@ def _trace_select(self, dates): class ConcatResult(Result): - def __init__(self, context, action_path, results): - super().__init__(context, action_path, dates=None) + def __init__(self, context, action_path, dates, results, **kwargs): + super().__init__(context, action_path, dates) self.results = [r for r in results if not r.empty] @cached_property @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 @@ -689,7 +690,12 @@ def __init__(self, context, action_path, previous_step, *args, **kwargs): class ConcatAction(ActionWithList): @trace_select def select(self, dates): - return ConcatResult(self.context, [a.select(dates) for a in self.actions]) + return ConcatResult( + self.context, + self.action_path, + dates, + [a.select(dates) for a in self.actions], + ) class JoinAction(ActionWithList): @@ -715,18 +721,18 @@ def __init__(self, context, action_path, **kwargs): else: subconfig[k] = v - self._dates = build_groups(datesconfig) + self.filtering_dates = build_groups(datesconfig) self.content = action_factory(subconfig, context, self.action_path + ["dates"]) @trace_select def select(self, dates): - newdates = self._dates.intersect(dates) + newdates = self.filtering_dates.intersect(dates) if newdates.empty(): - return EmptyResult(self.context, None, newdates) + return EmptyResult(self.context, self.action_path, newdates) return self.content.select(newdates) def __repr__(self): - return super().__repr__(f"{self._dates}\n{self.content}") + return super().__repr__(f"{self.filtering_dates}\n{self.content}") def merge_dicts(a, b): diff --git a/ecml_tools/create/loaders.py b/ecml_tools/create/loaders.py index 7e81fef..8f8be74 100644 --- a/ecml_tools/create/loaders.py +++ b/ecml_tools/create/loaders.py @@ -576,7 +576,8 @@ def add_total_size(self): self.update_metadata(total_size=size, total_number_of_files=n) + class CleanupLoader(Loader): def run(self): self.statistics_registry.delete() - self.registry.clean() \ No newline at end of file + self.registry.clean()