From e670617c633777e02db50a61c84862ec7af26024 Mon Sep 17 00:00:00 2001 From: nathanbijleveld Date: Fri, 26 Sep 2025 15:54:38 +0200 Subject: [PATCH 1/6] update true and false class --- pyiceberg/expressions/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyiceberg/expressions/__init__.py b/pyiceberg/expressions/__init__.py index 2adf898fea..81cd8059e6 100644 --- a/pyiceberg/expressions/__init__.py +++ b/pyiceberg/expressions/__init__.py @@ -39,9 +39,10 @@ literal, ) from pyiceberg.schema import Accessor, Schema -from pyiceberg.typedef import L, StructProtocol +from pyiceberg.typedef import L, StructProtocol, IcebergBaseModel, IcebergRootModel from pyiceberg.types import DoubleType, FloatType, NestedField from pyiceberg.utils.singleton import Singleton +from pydantic import model_serializer def _to_unbound_term(term: Union[str, UnboundTerm[Any]]) -> UnboundTerm[Any]: @@ -362,8 +363,9 @@ def __getnewargs__(self) -> Tuple[BooleanExpression]: return (self.child,) -class AlwaysTrue(BooleanExpression, Singleton): +class AlwaysTrue(BooleanExpression, Singleton, IcebergRootModel): """TRUE expression.""" + root: str = "true" def __invert__(self) -> AlwaysFalse: """Transform the Expression into its negated version.""" @@ -378,8 +380,9 @@ def __repr__(self) -> str: return "AlwaysTrue()" -class AlwaysFalse(BooleanExpression, Singleton): +class AlwaysFalse(BooleanExpression, Singleton, IcebergRootModel): """FALSE expression.""" + root: str = "false" def __invert__(self) -> AlwaysTrue: """Transform the Expression into its negated version.""" From 527fc42cee752cad45c724da81ad7c8f3f742ef7 Mon Sep 17 00:00:00 2001 From: nathanbijleveld Date: Fri, 26 Sep 2025 15:55:41 +0200 Subject: [PATCH 2/6] test serialization of true and false object --- tests/expressions/test_expressions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/expressions/test_expressions.py b/tests/expressions/test_expressions.py index 828d32704a..ac5411ffcd 100644 --- a/tests/expressions/test_expressions.py +++ b/tests/expressions/test_expressions.py @@ -738,6 +738,7 @@ def test_not() -> None: def test_always_true() -> None: always_true = AlwaysTrue() + assert always_true.model_dump_json() == '"true"' assert str(always_true) == "AlwaysTrue()" assert repr(always_true) == "AlwaysTrue()" assert always_true == eval(repr(always_true)) @@ -746,6 +747,7 @@ def test_always_true() -> None: def test_always_false() -> None: always_false = AlwaysFalse() + assert always_false.model_dump_json() == '"false"' assert str(always_false) == "AlwaysFalse()" assert repr(always_false) == "AlwaysFalse()" assert always_false == eval(repr(always_false)) From 650e293a5487c1b8b95f98e1f6d77e85758bfbca Mon Sep 17 00:00:00 2001 From: nathanbijleveld Date: Fri, 26 Sep 2025 16:02:12 +0200 Subject: [PATCH 3/6] remove unused import --- pyiceberg/expressions/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiceberg/expressions/__init__.py b/pyiceberg/expressions/__init__.py index 81cd8059e6..babef0efa6 100644 --- a/pyiceberg/expressions/__init__.py +++ b/pyiceberg/expressions/__init__.py @@ -39,7 +39,7 @@ literal, ) from pyiceberg.schema import Accessor, Schema -from pyiceberg.typedef import L, StructProtocol, IcebergBaseModel, IcebergRootModel +from pyiceberg.typedef import L, StructProtocol, IcebergRootModel from pyiceberg.types import DoubleType, FloatType, NestedField from pyiceberg.utils.singleton import Singleton from pydantic import model_serializer From e09245948f815eb20efaa552034bc5f73cf7c01e Mon Sep 17 00:00:00 2001 From: nathanbijleveld Date: Fri, 26 Sep 2025 16:06:16 +0200 Subject: [PATCH 4/6] remove unused model_serializer --- pyiceberg/expressions/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyiceberg/expressions/__init__.py b/pyiceberg/expressions/__init__.py index babef0efa6..727046bb97 100644 --- a/pyiceberg/expressions/__init__.py +++ b/pyiceberg/expressions/__init__.py @@ -42,7 +42,6 @@ from pyiceberg.typedef import L, StructProtocol, IcebergRootModel from pyiceberg.types import DoubleType, FloatType, NestedField from pyiceberg.utils.singleton import Singleton -from pydantic import model_serializer def _to_unbound_term(term: Union[str, UnboundTerm[Any]]) -> UnboundTerm[Any]: From 81ef2b092274b18e0a72c3cebfae1134060db08c Mon Sep 17 00:00:00 2001 From: Nathan Bijleveld Date: Thu, 2 Oct 2025 11:37:16 +0200 Subject: [PATCH 5/6] fix linting issues --- pyiceberg/expressions/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pyiceberg/expressions/__init__.py b/pyiceberg/expressions/__init__.py index 727046bb97..73f8662250 100644 --- a/pyiceberg/expressions/__init__.py +++ b/pyiceberg/expressions/__init__.py @@ -39,7 +39,7 @@ literal, ) from pyiceberg.schema import Accessor, Schema -from pyiceberg.typedef import L, StructProtocol, IcebergRootModel +from pyiceberg.typedef import IcebergRootModel, L, StructProtocol from pyiceberg.types import DoubleType, FloatType, NestedField from pyiceberg.utils.singleton import Singleton @@ -361,9 +361,10 @@ def __getnewargs__(self) -> Tuple[BooleanExpression]: """Pickle the Not class.""" return (self.child,) - -class AlwaysTrue(BooleanExpression, Singleton, IcebergRootModel): """TRUE expression.""" + + +class AlwaysTrue(BooleanExpression, Singleton, IcebergRootModel[str]): root: str = "true" def __invert__(self) -> AlwaysFalse: @@ -379,8 +380,9 @@ def __repr__(self) -> str: return "AlwaysTrue()" -class AlwaysFalse(BooleanExpression, Singleton, IcebergRootModel): +class AlwaysFalse(BooleanExpression, Singleton, IcebergRootModel[str]): """FALSE expression.""" + root: str = "false" def __invert__(self) -> AlwaysTrue: @@ -734,14 +736,14 @@ def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundLiteralPredi if isinstance(lit, AboveMax): if isinstance(self, (LessThan, LessThanOrEqual, NotEqualTo)): - return AlwaysTrue() # type: ignore + return AlwaysTrue() elif isinstance(self, (GreaterThan, GreaterThanOrEqual, EqualTo)): - return AlwaysFalse() # type: ignore + return AlwaysFalse() elif isinstance(lit, BelowMin): if isinstance(self, (GreaterThan, GreaterThanOrEqual, NotEqualTo)): - return AlwaysTrue() # type: ignore + return AlwaysTrue() elif isinstance(self, (LessThan, LessThanOrEqual, EqualTo)): - return AlwaysFalse() # type: ignore + return AlwaysFalse() return self.as_bound(bound_term, lit) From 6c8d689fd54dd3d61498526e561a65e38bd6261b Mon Sep 17 00:00:00 2001 From: Nathan Bijleveld Date: Thu, 2 Oct 2025 12:03:54 +0200 Subject: [PATCH 6/6] add docstring that got removed during fix of linting --- pyiceberg/expressions/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyiceberg/expressions/__init__.py b/pyiceberg/expressions/__init__.py index 73f8662250..cbebbd017e 100644 --- a/pyiceberg/expressions/__init__.py +++ b/pyiceberg/expressions/__init__.py @@ -365,6 +365,8 @@ def __getnewargs__(self) -> Tuple[BooleanExpression]: class AlwaysTrue(BooleanExpression, Singleton, IcebergRootModel[str]): + """TRUE expression.""" + root: str = "true" def __invert__(self) -> AlwaysFalse: