Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ This document explains the changes made to Iris for this release
attribute. Also made cell_method string parsing more lenient w.r.t.
whitespace. (:pull:`6083`)

#. `@ukmo-ccbunney`_ fixed comparison of cubes with array type attributes;
fixes :issue:`6027` (:pull:`6181`)

💣 Incompatible Changes
=======================

Expand Down
4 changes: 3 additions & 1 deletion lib/iris/_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ def _defn_msgs(self, other_defn):
diff_attrs = [
repr(key[1])
for key in attrs_1
if np.all(attrs_1[key] != attrs_2[key])
if not np.array_equal(
np.array(attrs_1[key], ndmin=1), np.array(attrs_2[key], ndmin=1)
)
]
diff_attrs = ", ".join(sorted(diff_attrs))
msgs.append(
Expand Down
9 changes: 4 additions & 5 deletions lib/iris/common/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import Any

import cf_units
import numpy as np

import iris.std_names

Expand Down Expand Up @@ -104,11 +105,9 @@ def __eq__(self, other):
match = set(self.keys()) == set(other.keys())
if match:
for key, value in self.items():
match = value == other[key]
try:
match = bool(match)
except ValueError:
match = match.all()
match = np.array_equal(
np.array(value, ndmin=1), np.array(other[key], ndmin=1)
)
if not match:
break
return match
Expand Down
10 changes: 10 additions & 0 deletions lib/iris/tests/unit/common/mixin/test_LimitedAttributeDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,22 @@ def test___eq___numpy(self):
right = LimitedAttributeDict(**values)
self.assertEqual(left, right)
self.assertEqual(left, values)

values = dict(one=np.arange(1), two=np.arange(1), three=np.arange(1))
left = LimitedAttributeDict(dict(one=0, two=0, three=0))
right = LimitedAttributeDict(**values)
self.assertEqual(left, right)
self.assertEqual(left, values)

# Test inequality:
values = dict(one=np.arange(1), two=np.arange(2), three=np.arange(3))
left = LimitedAttributeDict(**values)
right = LimitedAttributeDict(
one=np.arange(3), two=np.arange(2), three=np.arange(1)
)
self.assertNotEqual(left, right)
self.assertNotEqual(values, right)

def test___setitem__(self):
for key in self.forbidden_keys:
item = LimitedAttributeDict()
Expand Down