Fokko commented on code in PR #4324:
URL: https://github.com/apache/iceberg-python/pull/4324#discussion_r4529455604


##########
pyiceberg/manifest.py:
##########
@@ -736,6 +736,12 @@ def update(self, value: Any) -> None:
             else:
                 self._max = max(self._max, value)
                 self._min = min(self._min, value)
+                if isinstance(value, float) and value == 0.0:
+                    # min and max keep whichever zero came first, but bounds 
must order -0.0 below 0.0
+                    if math.copysign(1.0, value) < 0 and self._min == 0.0:
+                        self._min = value
+                    elif math.copysign(1.0, value) > 0 and self._max == 0.0:
+                        self._max = value

Review Comment:
   Ran a quick benchmark on this (CPython 3.14, best of 7 runs, 100k updates):
   
   | variant | ns/update |
   | --- | --- |
   | `key=` as written here | ~397 |
   | `key=`, key fn defined once outside | ~290 |
   | current PR (early exit for nonzero) | ~73 |
   
   So the `key=` form costs ~4x on the hot path — the tuple allocation + key 
call per comparison adds up — but both are sub-microsecond: for a realistic 
commit (10k files, 2 partition fields) that's ~0.2 ms difference. Correctness 
is identical between the two (verified both bounds on the zero edge cases). 
Either works, the current form just keeps the common path allocation-free. 
Thanks @dannycjones!



##########
pyiceberg/manifest.py:
##########
@@ -736,6 +736,12 @@ def update(self, value: Any) -> None:
             else:
                 self._max = max(self._max, value)
                 self._min = min(self._min, value)
+                if isinstance(value, float) and value == 0.0:
+                    # min and max keep whichever zero came first, but bounds 
must order -0.0 below 0.0
+                    if math.copysign(1.0, value) < 0 and self._min == 0.0:
+                        self._min = value
+                    elif math.copysign(1.0, value) > 0 and self._max == 0.0:
+                        self._max = value

Review Comment:
   Reposting as a thread reply — the previous attempt landed top-level. (Please 
ignore this one, see above.)



-- 
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]

Reply via email to