rambleraptor commented on code in PR #4280:
URL: https://github.com/apache/iceberg-python/pull/4280#discussion_r4474139371
##########
pyiceberg/typedef.py:
##########
@@ -173,6 +174,10 @@ class IcebergRootModel(RootModel[T], Generic[T]):
model_config = ConfigDict(frozen=True)
+def _is_nan(value: Any) -> bool:
Review Comment:
hot take, but we should make this a public method
(I'm changing my mind on this a bit after the full review, but this is a
great, simple method that's easy for people to understand + has value)
##########
pyiceberg/typedef.py:
##########
@@ -196,8 +201,15 @@ def __getitem__(self, pos: int) -> Any:
return self._data[pos]
def __eq__(self, other: Any) -> bool:
- """Return the equality of two instances of the Record class."""
- return self._data == other._data if isinstance(other, Record) else
False
+ """Compare records, treating NaN floats at the same position as
equal."""
Review Comment:
This is just an idea, but I'd love to hear what you think. This would help
readability a lot
```
def _is_nan(value: Any) -> bool:
return isinstance(value, float) and math.isnan(value)
def _same_value(a: Any, b: Any) -> bool:
return a is b or a == b or (_is_nan(a) and _is_nan(b))
class Record(StructProtocol):
def __eq__(self, other: Any) -> bool:
"""Compare records, treating NaN floats at the same position as
equal."""
if not isinstance(other, Record) or len(self._data) !=
len(other._data):
return False
return all(_same_value(a, b) for a, b in zip(self._data,
other._data, strict=True))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]