Skip to content

Commit 55ccae1

Browse files
committed
Simplify Record.__eq__ with a _same_value helper
Move the per-position comparison into a helper so `__eq__` reads as a single `all()` over the fields.
1 parent e987f5a commit 55ccae1

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎pyiceberg/typedef.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ def _is_nan(value: Any) -> bool:
178178
return isinstance(value, float) and math.isnan(value)
179179

180180

181+
def _same_value(a: Any, b: Any) -> bool:
182+
return a is b or a == b or (_is_nan(a) and _is_nan(b))
183+
184+
181185
class Record(StructProtocol):
182186
__slots__ = ("_data",)
183187
_data: list[Any]
@@ -204,12 +208,7 @@ def __eq__(self, other: Any) -> bool:
204208
"""Compare records, treating NaN floats at the same position as equal."""
205209
if not isinstance(other, Record) or len(self._data) != len(other._data):
206210
return False
207-
for a, b in zip(self._data, other._data, strict=True):
208-
if a is b or a == b:
209-
continue
210-
if not (_is_nan(a) and _is_nan(b)):
211-
return False
212-
return True
211+
return all(_same_value(a, b) for a, b in zip(self._data, other._data, strict=True))
213212

214213
def __repr__(self) -> str:
215214
"""Return the string representation of the Record class."""

0 commit comments

Comments
 (0)