jaimeferj commented on PR #2561:
URL: https://github.com/apache/iceberg-python/pull/2561#issuecomment-3369387018
Something fishy that I had to pull in order for tests to pass is putting the
attribute `term` as `Term[L]` instead of `UnboundTerm[Any]` as it was in
`UnboundPredicate`, father of `LiteralPredicate`. However, that also is
triggering mypy since we are changing types from father to child.
The problem is that the earlier implementation was calling
`_to_unbound_term` when initializing the instance, however, it does not always
return `UnboundTerm` as you can easily see from the implementation:
```Python
def _to_unbound_term(term: Union[str, UnboundTerm[Any]]) -> UnboundTerm[Any]:
return Reference(term) if isinstance(term, str) else term
```
If term is not `UnboundTerm` nor `str` the output is whatever the input was.
For example, as done in test `test_not_equal_to_invert` because it is being
initialized with a BoundRefence! If you use in the Pydantic model term as
`UnboundTerm[L]`:
```Python
_______________________________________________ test_not_equal_to_invert
_______________________________________________
def test_not_equal_to_invert() -> None:
> bound = NotEqualTo(
term=BoundReference( # type: ignore
field=NestedField(field_id=1, name="foo",
field_type=StringType(), required=False),
accessor=Accessor(position=0, inner=None),
),
literal="hello",
)
tests/expressions/test_expressions.py:431:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <[AttributeError("'NotEqualTo' object has no attribute 'term'")
raised in repr()] NotEqualTo object at 0x7f8d3405c550>
term = BoundReference(field=NestedField(field_id=1, name='foo',
field_type=StringType(), required=False),
accessor=Accessor(position=0,inner=None))
literal = 'hello'
def __init__(self, term: Union[str, UnboundTerm[Any]], literal: Union[L,
Literal[L]]): # pylint: disable=W0621
> super().__init__(term=_to_unbound_term(term),
literal=_to_literal(literal))
E pydantic_core._pydantic_core.ValidationError: 1 validation error for
NotEqualTo
E term
E Input should be an instance of UnboundTerm [type=is_instance_of,
input_value=BoundReference(field=Nest...(position=0,inner=None)),
input_type=BoundReference]
E For further information visit
https://errors.pydantic.dev/2.11/v/is_instance_of
pyiceberg/expressions/__init__.py:753: ValidationError
__________________________________________ test_greater_than_or_equal_invert
___________________________________________
def test_greater_than_or_equal_invert() -> None:
> bound = GreaterThanOrEqual(
term=BoundReference( # type: ignore
field=NestedField(field_id=1, name="foo",
field_type=StringType(), required=False),
accessor=Accessor(position=0, inner=None),
),
literal="hello",
)
```
Should we address this in this PR or delegate it to another issue?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]