Skip to content

Commit 091cc8c

Browse files
authored
Merge branch 'main' into feat/consistent-path-behaviour-on-outputs
2 parents 98328fb + ff222e2 commit 091cc8c

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ repos:
2727
- id: python-check-blanket-noqa # Check for # noqa: all
2828
- id: python-no-log-warn # Check for log.warn
2929
- repo: https://github.com/psf/black-pre-commit-mirror
30-
rev: 25.1.0
30+
rev: 25.9.0
3131
hooks:
3232
- id: black
3333
args: [--line-length=120]
3434
- repo: https://github.com/pycqa/isort
35-
rev: 6.0.1
35+
rev: 6.1.0
3636
hooks:
3737
- id: isort
3838
args:
@@ -41,7 +41,7 @@ repos:
4141
- --profile black
4242
- --project anemoi
4343
- repo: https://github.com/astral-sh/ruff-pre-commit
44-
rev: v0.12.11
44+
rev: v0.13.3
4545
hooks:
4646
- id: ruff
4747
args:
@@ -65,7 +65,7 @@ repos:
6565
- id: docconvert
6666
args: ["numpy"]
6767
- repo: https://github.com/tox-dev/pyproject-fmt
68-
rev: "v2.6.0"
68+
rev: "v2.7.0"
6969
hooks:
7070
- id: pyproject-fmt
7171
- repo: https://github.com/jshwi/docsig # Check docstrings against function sig

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ classifiers = [
4444
dynamic = [ "version" ]
4545
dependencies = [
4646
"anemoi-transform>0.1.13",
47-
"anemoi-utils[text,provenance]>=0.4.32",
47+
"anemoi-utils[provenance,text]>=0.4.32",
4848
"aniso8601",
4949
"anytree",
5050
"deprecation",
@@ -61,7 +61,7 @@ dependencies = [
6161

6262
optional-dependencies.all = [
6363
"anemoi-datasets",
64-
"anemoi-inference[huggingface,tests,zarr,plot]",
64+
"anemoi-inference[huggingface,plot,tests,zarr]",
6565
"anemoi-utils[all]>=0.4.32",
6666
]
6767
optional-dependencies.dev = [ "anemoi-inference[all,docs,plugin,tests]" ]

src/anemoi/inference/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ def patch(self, patch: dict) -> None:
11291129
def merge(main: dict[str, Any], patch: dict[str, Any]) -> None:
11301130

11311131
for k, v in patch.items():
1132-
if isinstance(v, dict):
1132+
if isinstance(v, dict) and isinstance(main.get(k, {}), dict):
11331133
if k not in main:
11341134
main[k] = {}
11351135
merge(main[k], v)

tests/unit/test_metadata.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# (C) Copyright 2025 Anemoi contributors.
2+
#
3+
# This software is licensed under the terms of the Apache Licence Version 2.0
4+
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5+
#
6+
# In applying this licence, ECMWF does not waive the privileges and immunities
7+
# granted to it by virtue of its status as an intergovernmental organisation
8+
# nor does it submit to any jurisdiction.
9+
10+
import pytest
11+
12+
from anemoi.inference.metadata import Metadata
13+
from anemoi.inference.testing.mock_checkpoint import mock_load_metadata
14+
15+
16+
@pytest.mark.parametrize(
17+
"initial, patch, expected",
18+
[
19+
(
20+
{"config": {"dataloader": {"dataset": "abc"}}},
21+
{"config": {"dataloader": {"something": {"else": "123"}}}},
22+
{"dataset": "abc", "something": {"else": "123"}},
23+
),
24+
(
25+
{"config": {"dataloader": [{"dataset": "abc"}, {"dataset": "xyz"}]}},
26+
{"config": {"dataloader": {"cutout": [{"dataset": "123"}, {"dataset": "456"}]}}},
27+
{"cutout": [{"dataset": "123"}, {"dataset": "456"}]},
28+
),
29+
(
30+
{"config": {"dataloader": "abc"}},
31+
{"config": {"dataloader": "xyz"}},
32+
"xyz",
33+
),
34+
],
35+
)
36+
def test_patch(initial, patch, expected):
37+
metadata = Metadata(initial)
38+
assert metadata._metadata == initial
39+
40+
metadata.patch(patch)
41+
assert metadata._metadata["config"]["dataloader"] == expected
42+
43+
44+
def test_constant_fields_patch():
45+
model_metadata = mock_load_metadata("unit/checkpoints/atmos.json", supporting_arrays=False)
46+
metadata = Metadata(model_metadata)
47+
48+
fields = ["z", "sdor", "slor", "lsm"]
49+
metadata.patch({"dataset": {"constant_fields": fields}})
50+
assert metadata._metadata["dataset"]["constant_fields"] == fields
51+
52+
# check that the rest of the metadata is still the same after patching
53+
metadata._metadata["dataset"].pop("constant_fields")
54+
assert model_metadata == metadata._metadata

0 commit comments

Comments
 (0)