Skip to content

Commit

Permalink
Remove extraneous comments
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Feb 18, 2025
1 parent cc24f0d commit 9cd0ccd
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@


def deep_equal(a, b):
"""Deep equality check w/ NaN e to handle array metadata serialization and deserialization behaviors"""
"""Deep equality check with handling of special cases for array metadata classes"""
if isinstance(a, (complex, np.complexfloating)) and isinstance(
b, (complex, np.complexfloating)
):
# Convert to Python float to force standard NaN handling.
a_real, a_imag = float(a.real), float(a.imag)
b_real, b_imag = float(b.real), float(b.imag)
# If both parts are NaN, consider them equal.
if np.isnan(a_real) and np.isnan(b_real):
real_eq = True
else:
Expand All @@ -47,38 +45,31 @@ def deep_equal(a, b):
imag_eq = a_imag == b_imag
return real_eq and imag_eq

# Handle floats (including numpy floating types) and treat NaNs as equal.
if isinstance(a, (float, np.floating)) and isinstance(b, (float, np.floating)):
if np.isnan(a) and np.isnan(b):
return True
return a == b

# Handle numpy.datetime64 values, treating NaT as equal.
if isinstance(a, np.datetime64) and isinstance(b, np.datetime64):
if np.isnat(a) and np.isnat(b):
return True
return a == b

# Handle numpy arrays.
if isinstance(a, np.ndarray) and isinstance(b, np.ndarray):
if a.shape != b.shape:
return False
# Compare elementwise.
return all(deep_equal(x, y) for x, y in zip(a.flat, b.flat, strict=False))

# Handle dictionaries.
if isinstance(a, dict) and isinstance(b, dict):
if set(a.keys()) != set(b.keys()):
return False
return all(deep_equal(a[k], b[k]) for k in a)

# Handle lists and tuples.
if isinstance(a, (list, tuple)) and isinstance(b, (list, tuple)):
if len(a) != len(b):
return False
return all(deep_equal(x, y) for x, y in zip(a, b, strict=False))

# Fallback to default equality.
return a == b


Expand Down Expand Up @@ -211,7 +202,6 @@ def test_meta_roundtrip(data: st.DataObject, zarr_format: int) -> None:
zarray_dict = json.loads(buffer_dict[ZARR_JSON].to_bytes().decode())
metadata_roundtripped = ArrayV3Metadata.from_dict(zarray_dict)

# Convert both metadata instances to dictionaries.
orig = dataclasses.asdict(metadata)
rt = dataclasses.asdict(metadata_roundtripped)

Expand Down

0 comments on commit 9cd0ccd

Please sign in to comment.