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

Commit

Permalink
Merge branch 'develop' of https://github.com/ecmwf-lab/ecml-tools int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
floriankrb committed Feb 27, 2024
2 parents d59d401 + 74651c8 commit 7e016dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ecml_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

__version__ = "0.4.7"
__version__ = "0.5.0"
19 changes: 12 additions & 7 deletions ecml_tools/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,9 @@ def frequency(self):
def source(self, index):
return Source(self, index, self.forward.source(index))

def __repr__(self):
return f"Subset({self.dates[0]}, {self.dates[-1]}, {self.frequency})"


class Select(Forwards):
"""
Expand Down Expand Up @@ -1317,8 +1320,8 @@ def _auto_adjust(datasets, kwargs):
"""Adjust the datasets for concatenation or joining based
on parameters set to 'matching'"""

if kwargs.get("ajust") == "matching":
kwargs.pop("ajust")
if kwargs.get("adjust") == "matching":
kwargs.pop("adjust")
for p in ("select", "frequency", "start", "end"):
kwargs[p] = "matching"

Expand All @@ -1327,27 +1330,29 @@ def _auto_adjust(datasets, kwargs):
if kwargs.get("select") == "matching":
kwargs.pop("select")
variables = None

for d in datasets:
if variables is None:
variables = set(d.variables)
else:
variables &= set(d.variables)

if len(variables) == 0:
raise ValueError("No common variables")

adjust["select"] = sorted(variables)

if kwargs.get("frequency") == "matching":
kwargs.pop("frequency")
adjust["frequency"] = max(d.frequency for d in datasets)

if kwargs.get("start") == "matching":
kwargs.pop("start")
adjust["start"] = max(d.dates[0] for d in datasets).astype(object)

if kwargs.get("end") == "matching":
kwargs.pop("end")
adjust["end"] = max(d.dates[-1] for d in datasets).astype(object)
adjust["end"] = min(d.dates[-1] for d in datasets).astype(object)

if kwargs.get("frequency") == "matching":
kwargs.pop("frequency")
adjust["frequency"] = max(d.frequency for d in datasets)

if adjust:
datasets = [d._subset(**adjust) for d in datasets]
Expand Down

0 comments on commit 7e016dd

Please sign in to comment.