diff --git a/pyiceberg/schema.py b/pyiceberg/schema.py index a79b3ae95f..99f983074b 100644 --- a/pyiceberg/schema.py +++ b/pyiceberg/schema.py @@ -115,16 +115,13 @@ def __len__(self) -> int: 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 872e95ce36..f9c928c9e6 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: