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: 2 additions & 2 deletions pyiceberg/expressions/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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]:
Expand Down
28 changes: 28 additions & 0 deletions tests/expressions/test_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to verify that LongAboveMax is a singleton?

assert str(a) == "LongAboveMax"
assert repr(a) == "LongAboveMax()"
Comment on lines +640 to +641

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation of these assertions?

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),
Expand Down