Skip to content

Commit 3ec4fac

Browse files
committed
Return overflow sentinel in LongLiteral.to(FloatType)
1 parent d101879 commit 3ec4fac

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

pyiceberg/expressions/literals.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ def _(self, _: IntegerType) -> Literal[int]:
317317

318318
@to.register(FloatType)
319319
def _(self, _: FloatType) -> Literal[float]:
320+
if self.value > FloatType.max:
321+
return FloatAboveMax()
322+
elif self.value < FloatType.min:
323+
return FloatBelowMin()
320324
return FloatLiteral(float(self.value))
321325

322326
@to.register(DoubleType)

tests/expressions/test_literals.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ def test_long_to_float_conversion() -> None:
184184
assert lit.value == float_lit.value
185185

186186

187+
def test_long_to_float_outside_bound() -> None:
188+
big_lit = literal(10**39)
189+
above_max_lit = big_lit.to(FloatType())
190+
assert above_max_lit == FloatAboveMax()
191+
192+
small_lit = literal(-(10**39))
193+
below_min_lit = small_lit.to(FloatType())
194+
assert below_min_lit == FloatBelowMin()
195+
196+
187197
def test_long_to_double_conversion() -> None:
188198
lit = literal(34).to(LongType())
189199
dbl_lit = lit.to(DoubleType())

0 commit comments

Comments
 (0)