Skip to content

Commit 110e4e3

Browse files
committed
Make SetPredicate and subclasses JSON serializable
1 parent 6482846 commit 110e4e3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,14 @@ def as_bound(self) -> Type[BoundNotNaN[L]]:
577577
return BoundNotNaN[L]
578578

579579

580-
class SetPredicate(UnboundPredicate[L], IcebergBaseModel, ABC):
580+
class SetPredicate(IcebergBaseModel, UnboundPredicate[L], ABC):
581581
model_config = ConfigDict(arbitrary_types_allowed=True)
582582

583-
type: TypingLiteral["in", "not-in"] = Field(default="in", alias="type")
583+
type: TypingLiteral["in", "not-in"] = Field(default="in")
584584
literals: Set[Literal[L]] = Field(alias="items")
585585

586586
def __init__(self, term: Union[str, UnboundTerm[Any]], literals: Union[Iterable[L], Iterable[Literal[L]]]):
587-
super().__init__(term)
588-
self.literals = _to_literal_set(literals)
587+
super().__init__(term=_to_unbound_term(term), items=_to_literal_set(literals)) # type: ignore
589588

590589
def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundSetPredicate[L]:
591590
bound_term = self.term.bind(schema, case_sensitive)
@@ -737,7 +736,7 @@ def __new__( # type: ignore # pylint: disable=W0221
737736

738737
def __invert__(self) -> In[L]:
739738
"""Transform the Expression into its negated version."""
740-
return NotIn[L](self.term, self.literals)
739+
return In[L](self.term, self.literals)
741740

742741
@property
743742
def as_bound(self) -> Type[BoundNotIn[L]]:

tests/expressions/test_expressions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,12 +875,12 @@ def test_not_in() -> None:
875875

876876
def test_serialize_in() -> None:
877877
pred = In(term="foo", literals=[1, 2, 3])
878-
assert pred.model_dump_json() == '{"type":"in","term":"foo","value":[1,2,3]}'
878+
assert pred.model_dump_json() == '{"term":"foo","type":"in","items":[1,2,3]}'
879879

880880

881881
def test_serialize_not_in() -> None:
882882
pred = NotIn(term="foo", literals=[1, 2, 3])
883-
assert pred.model_dump_json() == '{"type":"not-in","term":"foo","value":[1,2,3]}'
883+
assert pred.model_dump_json() == '{"term":"foo","type":"not-in","items":[1,2,3]}'
884884

885885

886886
def test_bound_equal_to(term: BoundReference[Any]) -> None:

0 commit comments

Comments
 (0)