diff --git a/pyiceberg/expressions/literals.py b/pyiceberg/expressions/literals.py index 20be711c02..39922fde33 100644 --- a/pyiceberg/expressions/literals.py +++ b/pyiceberg/expressions/literals.py @@ -251,7 +251,7 @@ def __init__(self) -> None: @singledispatchmethod def to(self, type_var: IcebergType) -> Literal: # type: ignore - raise TypeError("Cannot change the type of IntAboveMax") + raise TypeError("Cannot change the type of LongAboveMax") @to.register(LongType) def _(self, _: LongType) -> Literal[int]: @@ -264,7 +264,7 @@ def __init__(self) -> None: @singledispatchmethod def to(self, type_var: IcebergType) -> Literal: # type: ignore - raise TypeError("Cannot change the type of IntBelowMin") + raise TypeError("Cannot change the type of LongBelowMin") @to.register(LongType) def _(self, _: LongType) -> Literal[int]: diff --git a/tests/expressions/test_literals.py b/tests/expressions/test_literals.py index 33b41d5e4c..1cfa2a6a65 100644 --- a/tests/expressions/test_literals.py +++ b/tests/expressions/test_literals.py @@ -633,6 +633,34 @@ def test_below_min_int() -> None: assert b.to(IntegerType()) == IntBelowMin() +def test_above_max_long() -> None: + a = LongAboveMax() + # singleton + assert a == LongAboveMax() + assert str(a) == "LongAboveMax" + assert repr(a) == "LongAboveMax()" + assert a.value == LongType.max + assert a == eval(repr(a)) + assert a.to(LongType()) == LongAboveMax() + with pytest.raises(TypeError) as e: + a.to(IntegerType()) + assert "Cannot change the type of LongAboveMax" in str(e.value) + + +def test_below_min_long() -> None: + b = LongBelowMin() + # singleton + assert b == LongBelowMin() + assert str(b) == "LongBelowMin" + assert repr(b) == "LongBelowMin()" + assert b == eval(repr(b)) + assert b.value == LongType.min + assert b.to(LongType()) == LongBelowMin() + with pytest.raises(TypeError) as e: + b.to(IntegerType()) + assert "Cannot change the type of LongBelowMin" in str(e.value) + + def test_invalid_boolean_conversions() -> None: assert_invalid_conversions( literal(True),