This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-3958-dc4e3f85c8b1c356c48597f32b0246e0af9842a8 in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
commit 07099ee180db9a1e89fc55d21bcac21b7a33e2f9 Author: Kevin Liu <[email protected]> AuthorDate: Thu Sep 24 20:10:25 2026 +0000 Fix schema equality for empty schemas and identifier fields (#3958) * Fix schema equality for empty schemas and identifier fields Co-authored-by: Copilot App <[email protected]> * Use loops for schema equality regression cases Co-authored-by: Copilot App <[email protected]> * Keep schema equality tests focused on regressions Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: Copilot App <[email protected]> --- pyiceberg/schema.py | 5 +---- tests/test_schema.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pyiceberg/schema.py b/pyiceberg/schema.py index a79b3ae95..99f983074 100644 --- a/pyiceberg/schema.py +++ b/pyiceberg/schema.py @@ -115,16 +115,13 @@ class Schema(IcebergBaseModel): def __eq__(self, other: Any) -> bool: """Return the equality of two instances of the Schema class.""" - if not other: - return False - if not isinstance(other, Schema): return False if len(self.columns) != len(other.columns): return False - identifier_field_ids_is_equal = self.identifier_field_ids == other.identifier_field_ids + identifier_field_ids_is_equal = set(self.identifier_field_ids) == set(other.identifier_field_ids) schema_is_equal = all(lhs == rhs for lhs, rhs in zip(self.columns, other.columns, strict=True)) return identifier_field_ids_is_equal and schema_is_equal diff --git a/tests/test_schema.py b/tests/test_schema.py index dcd54cd49..94931277b 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -119,6 +119,18 @@ def test_schema_repr_two_fields() -> None: assert expected == actual +def test_empty_schema_equality() -> None: + assert Schema() == Schema() + + +def test_schema_equality_ignores_identifier_field_order() -> None: + fields = ( + NestedField(field_id=1, name="foo", field_type=LongType(), required=True), + NestedField(field_id=2, name="bar", field_type=LongType(), required=True), + ) + assert Schema(*fields, identifier_field_ids=[1, 2]) == Schema(*fields, identifier_field_ids=[2, 1]) + + def test_schema_raise_on_duplicate_names() -> None: """Test schema representation""" with pytest.raises(ValueError) as exc_info:
