You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ke...@apache.org on 2026/06/21 21:14:15 UTC
(iceberg-python) branch main updated: Return overflow sentinel in LongLiteral.to(FloatType) (#3502)
This is an automated email from the ASF dual-hosted git repository.
kevinjqliu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new 43b27e4f5 Return overflow sentinel in LongLiteral.to(FloatType) (#3502)
43b27e4f5 is described below
commit 43b27e4f59c7d25210c5cf1d95c09ccaba14f15a
Author: Yuya Ebihara <eb...@gmail.com>
AuthorDate: Mon Jun 22 06:14:10 2026 +0900
Return overflow sentinel in LongLiteral.to(FloatType) (#3502)
# Rationale for this change
- Fixes #3494
## Are these changes tested?
Yes, added assertions fail if we revert this PR's change.
## Are there any user-facing changes?
Yes, users receive an overflow sentinel instead of OverflowError.
<!-- In the case of user-facing changes, please add the changelog label.
-->
---------
Co-authored-by: Kevin Liu <ke...@users.noreply.github.com>
---
pyiceberg/expressions/literals.py | 4 ++++
tests/expressions/test_literals.py | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/pyiceberg/expressions/literals.py b/pyiceberg/expressions/literals.py
index 1ff800852..fec06aa79 100644
--- a/pyiceberg/expressions/literals.py
+++ b/pyiceberg/expressions/literals.py
@@ -317,6 +317,10 @@ class LongLiteral(Literal[int]):
@to.register(FloatType)
def _(self, _: FloatType) -> Literal[float]:
+ if FloatType.max < self.value:
+ return FloatAboveMax()
+ elif self.value < FloatType.min:
+ return FloatBelowMin()
return FloatLiteral(float(self.value))
@to.register(DoubleType)
diff --git a/tests/expressions/test_literals.py b/tests/expressions/test_literals.py
index de9d39077..1b88ef207 100644
--- a/tests/expressions/test_literals.py
+++ b/tests/expressions/test_literals.py
@@ -184,6 +184,16 @@ def test_long_to_float_conversion() -> None:
assert lit.value == float_lit.value
+def test_long_to_float_outside_bound() -> None:
+ big_lit = literal(10**39)
+ above_max_lit = big_lit.to(FloatType())
+ assert above_max_lit == FloatAboveMax()
+
+ small_lit = literal(-(10**39))
+ below_min_lit = small_lit.to(FloatType())
+ assert below_min_lit == FloatBelowMin()
+
+
def test_long_to_double_conversion() -> None:
lit = literal(34).to(LongType())
dbl_lit = lit.to(DoubleType())