Fokko commented on code in PR #4331:
URL: https://github.com/apache/iceberg-python/pull/4331#discussion_r4555651690
##########
pyiceberg/io/pyarrow.py:
##########
@@ -2381,13 +2381,31 @@ def update_min(self, val: Any | None) -> None:
if self.current_min is None:
self.current_min = val
elif val is not None:
+ previous = self.current_min
self.current_min = min(val, self.current_min)
+ if (
+ isinstance(val, float)
+ and val == 0.0
+ and isinstance(previous, float)
+ and math.copysign(1.0, previous) < math.copysign(1.0,
self.current_min)
+ ):
+ # min keeps whichever zero came first, but bounds must order
-0.0 below 0.0
+ self.current_min = previous
def update_max(self, val: Any | None) -> None:
if self.current_max is None:
self.current_max = val
elif val is not None:
+ previous = self.current_max
self.current_max = max(val, self.current_max)
+ if (
+ isinstance(val, float)
+ and val == 0.0
+ and isinstance(previous, float)
+ and math.copysign(1.0, previous) > math.copysign(1.0,
self.current_max)
+ ):
+ # max keeps whichever zero came first, but bounds must order
-0.0 below 0.0
+ self.current_max = previous
Review Comment:
Same for `update_max`:
```suggestion
self.current_max = max(self.current_max, val)
if isinstance(val, float) and val == 0.0 and math.copysign(1.0,
val) > 0 and self.current_max == 0.0:
# max keeps the existing zero on a tie, but bounds must
order -0.0 below 0.0
self.current_max = val
```
##########
pyiceberg/io/pyarrow.py:
##########
@@ -2381,13 +2381,31 @@ def update_min(self, val: Any | None) -> None:
if self.current_min is None:
self.current_min = val
elif val is not None:
+ previous = self.current_min
self.current_min = min(val, self.current_min)
+ if (
+ isinstance(val, float)
+ and val == 0.0
+ and isinstance(previous, float)
+ and math.copysign(1.0, previous) < math.copysign(1.0,
self.current_min)
+ ):
+ # min keeps whichever zero came first, but bounds must order
-0.0 below 0.0
+ self.current_min = previous
Review Comment:
How about flipping the argument order so a tie keeps the existing value,
like `PartitionFieldStats.update` in `manifest.py`? Then the guard only needs
to handle an incoming `-0.0`, and we can drop `previous`:
```suggestion
self.current_min = min(self.current_min, val)
if isinstance(val, float) and val == 0.0 and math.copysign(1.0,
val) < 0 and self.current_min == 0.0:
# min keeps the existing zero on a tie, but bounds must
order -0.0 below 0.0
self.current_min = val
```
This also makes the comment accurate. With `min(val, self.current_min)`, the
zero that arrived last wins on a tie, not the first one.
--
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]