Skip to content

Commit

Permalink
Do not use Path objects as configuration dictionary keys to avoid e…
Browse files Browse the repository at this point in the history
…rrors in `dask.config.merge` (#2578)

Co-authored-by: Valeriu Predoi <[email protected]>
  • Loading branch information
schlunma and valeriupredoi authored Nov 12, 2024
1 parent 7892678 commit a328578
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion esmvalcore/config/_config_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,13 @@ def validate_rootpath(value):
new_mapping[key] = validate_pathlist(paths)
else:
validate_dict(paths)

# dask.config.merge cannot handle pathlib.Path objects as dict keys
# -> we convert the validated Path back to a string and handle this
# downstream in local.py (see also
# https://github.com/ESMValGroup/ESMValCore/issues/2577)
new_mapping[key] = {
validate_path(path): validate_string(drs)
str(validate_path(path)): validate_string(drs)
for path, drs in paths.items()
}

Expand Down
1 change: 1 addition & 0 deletions esmvalcore/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def _get_data_sources(project: str) -> list[DataSource]:
paths = {p: structure for p in paths}
sources: list[DataSource] = []
for path, structure in paths.items():
path = Path(path)
dir_templates = _select_drs("input_dir", project, structure)
file_templates = _select_drs("input_file", project, structure)
sources.extend(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/config/test_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def generate_validator_testcases(valid):
},
{
"CMIP6": {
Path("/a"): "DKRZ",
Path("/b"): "ESGF",
"/a": "DKRZ",
"/b": "ESGF",
},
},
),
Expand Down

0 comments on commit a328578

Please sign in to comment.