2929
3030
3131def deep_equal (a , b ):
32- """Deep equality check w/ NaN e to handle array metadata serialization and deserialization behaviors """
32+ """Deep equality check with handling of special cases for array metadata classes """
3333 if isinstance (a , (complex , np .complexfloating )) and isinstance (
3434 b , (complex , np .complexfloating )
3535 ):
36- # Convert to Python float to force standard NaN handling.
3736 a_real , a_imag = float (a .real ), float (a .imag )
3837 b_real , b_imag = float (b .real ), float (b .imag )
39- # If both parts are NaN, consider them equal.
4038 if np .isnan (a_real ) and np .isnan (b_real ):
4139 real_eq = True
4240 else :
@@ -47,38 +45,31 @@ def deep_equal(a, b):
4745 imag_eq = a_imag == b_imag
4846 return real_eq and imag_eq
4947
50- # Handle floats (including numpy floating types) and treat NaNs as equal.
5148 if isinstance (a , (float , np .floating )) and isinstance (b , (float , np .floating )):
5249 if np .isnan (a ) and np .isnan (b ):
5350 return True
5451 return a == b
5552
56- # Handle numpy.datetime64 values, treating NaT as equal.
5753 if isinstance (a , np .datetime64 ) and isinstance (b , np .datetime64 ):
5854 if np .isnat (a ) and np .isnat (b ):
5955 return True
6056 return a == b
6157
62- # Handle numpy arrays.
6358 if isinstance (a , np .ndarray ) and isinstance (b , np .ndarray ):
6459 if a .shape != b .shape :
6560 return False
66- # Compare elementwise.
6761 return all (deep_equal (x , y ) for x , y in zip (a .flat , b .flat , strict = False ))
6862
69- # Handle dictionaries.
7063 if isinstance (a , dict ) and isinstance (b , dict ):
7164 if set (a .keys ()) != set (b .keys ()):
7265 return False
7366 return all (deep_equal (a [k ], b [k ]) for k in a )
7467
75- # Handle lists and tuples.
7668 if isinstance (a , (list , tuple )) and isinstance (b , (list , tuple )):
7769 if len (a ) != len (b ):
7870 return False
7971 return all (deep_equal (x , y ) for x , y in zip (a , b , strict = False ))
8072
81- # Fallback to default equality.
8273 return a == b
8374
8475
@@ -211,7 +202,6 @@ def test_meta_roundtrip(data: st.DataObject, zarr_format: int) -> None:
211202 zarray_dict = json .loads (buffer_dict [ZARR_JSON ].to_bytes ().decode ())
212203 metadata_roundtripped = ArrayV3Metadata .from_dict (zarray_dict )
213204
214- # Convert both metadata instances to dictionaries.
215205 orig = dataclasses .asdict (metadata )
216206 rt = dataclasses .asdict (metadata_roundtripped )
217207
0 commit comments