Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyiceberg/expressions/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ def _(self, _: IntegerType) -> Literal[int]:

@to.register(FloatType)
def _(self, _: FloatType) -> Literal[float]:
if FloatType.max < self.value:
return FloatAboveMax()
elif FloatType.min > self.value:
return FloatBelowMin()
return FloatLiteral(float(self.value))

@to.register(DoubleType)
Expand Down
10 changes: 10 additions & 0 deletions tests/expressions/test_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down