Skip to content

Commit

Permalink
Common metadata ops support mixed split/unsplit attribute dicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo committed Aug 24, 2023
1 parent 76a3974 commit d06f589
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/src/further_topics/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ Let's reinforce this behaviour, but this time by combining metadata where the
>>> metadata != cube.metadata
True
>>> metadata.combine(cube.metadata).attributes
{'Model scenario': 'A1B'}
CubeAttrsDict(globals={}, locals={'Model scenario': 'A1B'})

The combined result for the ``attributes`` member only contains those
**common keys** with **common values**.
Expand Down
15 changes: 11 additions & 4 deletions lib/iris/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,20 @@ def xd_from_normal(dic):

def xd_normalise_input_pair(left, right):
"""Work out whether inputs are "split" type, and convert if so."""
is_split = xd_is_split(left)
from iris.cube import CubeAttrsDict

left_split, right_split = xd_is_split(left), xd_is_split(right)
is_split = left_split or right_split
if is_split:
assert xd_is_split(right)
# Convert any "normal" dicts to split equivalents first
# - this divides contents into global+local according to default rules
if not left_split:
left = CubeAttrsDict(left)
if not right_split:
right = CubeAttrsDict(right)
# convert both to paired-key form for calculations
left = xd_to_normal(left)
right = xd_to_normal(right)
else:
assert not xd_is_split(right)

return is_split, left, right

Expand Down

0 comments on commit d06f589

Please sign in to comment.