Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More reliable datasets to recipe conversion #2472

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions esmvalcore/_recipe/from_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import itertools
import logging
import re
from collections.abc import Iterable, Mapping, Sequence
from functools import partial
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, Iterable, Mapping, Sequence
from typing import TYPE_CHECKING, Any, Dict

from nested_lookup import nested_delete

Expand Down Expand Up @@ -99,10 +100,12 @@ def _move_datasets_up(recipe: Recipe) -> Recipe:

def _to_frozen(item):
"""Return a frozen and sorted copy of nested dicts and lists."""
if isinstance(item, list):
return tuple(sorted(_to_frozen(elem) for elem in item))
if isinstance(item, dict):
if isinstance(item, str):
return item
if isinstance(item, Mapping):
return tuple(sorted((k, _to_frozen(v)) for k, v in item.items()))
if isinstance(item, Iterable):
return tuple(sorted(_to_frozen(elem) for elem in item))
return item


Expand Down