From 58c020938e8e5d3de831580b8619e8ba0b4c94ba Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Thu, 20 Nov 2025 22:04:20 +0100 Subject: [PATCH 1/3] Restore previous timerange behaviour and remove some outdated code --- esmvalcore/_recipe/check.py | 5 +++-- esmvalcore/dataset.py | 5 +---- esmvalcore/local.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/esmvalcore/_recipe/check.py b/esmvalcore/_recipe/check.py index 55e1b52709..ea528c71f8 100644 --- a/esmvalcore/_recipe/check.py +++ b/esmvalcore/_recipe/check.py @@ -239,8 +239,9 @@ def data_availability(dataset: Dataset, log: bool = True) -> None: msg = f"Missing data for {dataset.summary(True)}" raise InputFilesNotFound(msg) - if "timerange" not in facets or any( - "timerange" not in f.facets for f in input_files + if ( + "*" in facets.get("timerange", "*") # type: ignore[operator] + or any("timerange" not in f.facets for f in input_files) ): return diff --git a/esmvalcore/dataset.py b/esmvalcore/dataset.py index 5c799d0843..3d1083b331 100644 --- a/esmvalcore/dataset.py +++ b/esmvalcore/dataset.py @@ -230,10 +230,6 @@ def _get_available_datasets(self) -> Iterator[Dataset]: """ dataset_template = self.copy() dataset_template.supplementaries = [] - if _isglob(dataset_template.facets.get("timerange")): - # Remove wildcard `timerange` facet, because data finding cannot - # handle it - dataset_template.facets.pop("timerange") seen = set() partially_defined = [] @@ -960,6 +956,7 @@ def _update_timerange(self) -> None: dataset.supplementaries = [] dataset.augment_facets() if "timerange" not in dataset.facets: + # timerange facet may be removed in augment_facets for time-independent data. self.facets.pop("timerange", None) return diff --git a/esmvalcore/local.py b/esmvalcore/local.py index bb0b2049f1..e8d63abcc7 100644 --- a/esmvalcore/local.py +++ b/esmvalcore/local.py @@ -594,7 +594,7 @@ def find_data(self, **facets: FacetValue) -> list[LocalFile]: file.facets.update( self._path2facets( file, - add_timerange="timerange" in facets, + add_timerange=facets.get("frequency", "fx") != "fx", ), ) file.ignore_warnings = self.ignore_warnings From fbe09fc56064e839e6a9667207ce5a4db21162d9 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Mon, 24 Nov 2025 11:53:36 +0100 Subject: [PATCH 2/3] Add test --- tests/integration/dataset/test_dataset.py | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/integration/dataset/test_dataset.py b/tests/integration/dataset/test_dataset.py index 8558e1de28..840614f407 100644 --- a/tests/integration/dataset/test_dataset.py +++ b/tests/integration/dataset/test_dataset.py @@ -61,6 +61,33 @@ def example_data_source(tmp_path: Path) -> dict[str, str]: } +@pytest.mark.parametrize("timerange", ["1850/185002", "*", "*/P2M"]) +def test_find_data( + example_data_source: dict[str, str], + session: Session, + timerange: str, +) -> None: + tas = Dataset( + short_name="tas", + mip="Amon", + project="CMIP5", + dataset="CanESM2", + ensemble="r1i1p1", + exp="historical", + timerange=timerange, + ) + tas.add_supplementary(short_name="areacella", mip="fx", ensemble="r0i0p0") + tas.session = session + tas.session["projects"]["CMIP5"]["data"] = { + "example-data-source": example_data_source, + } + + assert len(tas.files) == 1 + assert "timerange" in tas.files[0].facets + assert len(tas.supplementaries[0].files) == 1 + assert "timerange" not in tas.supplementaries[0].files + + def test_load(example_data_source: dict[str, str], session: Session) -> None: tas = Dataset( short_name="tas", From 97f242274ed9e426395ccb2d5fc714bd6a3f27f0 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Wed, 26 Nov 2025 07:48:23 +0100 Subject: [PATCH 3/3] Add another test case --- tests/integration/dataset/test_dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/dataset/test_dataset.py b/tests/integration/dataset/test_dataset.py index 840614f407..5bbb7e22d3 100644 --- a/tests/integration/dataset/test_dataset.py +++ b/tests/integration/dataset/test_dataset.py @@ -61,7 +61,7 @@ def example_data_source(tmp_path: Path) -> dict[str, str]: } -@pytest.mark.parametrize("timerange", ["1850/185002", "*", "*/P2M"]) +@pytest.mark.parametrize("timerange", ["1850/185002", "*", "*/P2M", "1860/*"]) def test_find_data( example_data_source: dict[str, str], session: Session,