@@ -938,10 +938,18 @@ def _make_names(prefixes):
938
938
939
939
def _check_unchanged (old , new ):
940
940
# Check data array attributes or global dataset attributes
941
+ def _check_attrs_equal (o , n ):
942
+ # Compare values and keys,
943
+ # But not ids : allow for copied values (see #365)
944
+ assert o .keys () == n .keys ()
945
+ for k , v in o .items ():
946
+ if isinstance (v , np .ndarray ):
947
+ assert np .all (v == n [k ])
948
+ else :
949
+ assert v == n [k ]
950
+
941
951
assert type (old ) == type (new )
942
- assert old .attrs .keys () == new .attrs .keys () # set comparison
943
- for att , old_val in old .attrs .items ():
944
- assert id (old_val ) == id (new .attrs [att ])
952
+ _check_attrs_equal (old .attrs , new .attrs )
945
953
946
954
# Check coordinate attributes and data variable attributes
947
955
dicts = [(old .coords , new .coords )]
@@ -951,9 +959,7 @@ def _check_unchanged(old, new):
951
959
assert old_dict .keys () == new_dict .keys () # set comparison
952
960
for key , old_obj in old_dict .items ():
953
961
new_obj = new_dict [key ]
954
- assert old_obj .attrs .keys () == new_obj .attrs .keys () # set comparison
955
- for att , old_val in old_obj .attrs .items ():
956
- assert id (old_val ) == id (new_obj .attrs [att ]) # numpy-safe comparison
962
+ _check_attrs_equal (old_obj .attrs , new_obj .attrs )
957
963
958
964
959
965
_TIME_NAMES = ["t" ] + _make_names (
0 commit comments