Skip to content

Commit e311187

Browse files
authored
Avoid modifying supplementary variables (#2992)
1 parent 3208f5f commit e311187

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

esmvalcore/_recipe/to_datasets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,5 +599,7 @@ def _representative_datasets(dataset: Dataset) -> list[Dataset]:
599599
copy.supplementaries = []
600600
representative_datasets = _get_input_datasets(copy)
601601
for representative_dataset in representative_datasets:
602-
representative_dataset.supplementaries = dataset.supplementaries
602+
representative_dataset.supplementaries = [
603+
d.copy() for d in dataset.supplementaries
604+
]
603605
return representative_datasets

tests/integration/recipe/test_recipe.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,64 @@ def simulate_diagnostic_run(diagnostic_task):
15051505
return record
15061506

15071507

1508+
def test_preprocessor_file_ancestors_are_input_files(
1509+
tmp_path: Path,
1510+
patched_datafinder: None,
1511+
session: Session,
1512+
) -> None:
1513+
"""Test that the ancestors of a preprocessor file are the input files."""
1514+
content = dedent("""
1515+
datasets:
1516+
- dataset: BCC-ESM1
1517+
project: CMIP6
1518+
exp: historical
1519+
ensemble: r1i1p1f1
1520+
grid: gn
1521+
supplementary_variables:
1522+
- short_name: sftlf
1523+
mip: fx
1524+
exp: 1pctCO2
1525+
- dataset: bcc-csm1-1
1526+
project: CMIP5
1527+
exp: historical
1528+
ensemble: r1i1p1
1529+
supplementary_variables:
1530+
- short_name: sftlf
1531+
mip: fx
1532+
ensemble: r0i0p0
1533+
1534+
preprocessors:
1535+
regrid:
1536+
regrid:
1537+
target_grid: BCC-ESM1
1538+
scheme: linear
1539+
1540+
diagnostics:
1541+
diagnostic_name:
1542+
variables:
1543+
tas:
1544+
preprocessor: regrid
1545+
mip: Amon
1546+
timerange: 2000/2005
1547+
scripts: null
1548+
""")
1549+
recipe = get_recipe(tmp_path, content, session)
1550+
assert len(recipe.tasks) == 1
1551+
task = next(iter(recipe.tasks))
1552+
assert len(task.products) == 2
1553+
for preprocessor_file in task.products:
1554+
assert len(preprocessor_file.datasets) == 1
1555+
dataset = preprocessor_file.datasets[0]
1556+
assert len(dataset.files) == 1
1557+
assert len(dataset.supplementaries[0].files) == 1
1558+
assert len(preprocessor_file._ancestors) == 2
1559+
assert dataset.files[0] is preprocessor_file._ancestors[0].filename
1560+
assert (
1561+
dataset.supplementaries[0].files[0]
1562+
is preprocessor_file._ancestors[1].filename
1563+
)
1564+
1565+
15081566
def test_diagnostic_task_provenance(
15091567
tmp_path,
15101568
patched_datafinder,

0 commit comments

Comments
 (0)