Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pyiceberg/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't dug into this at all, but what if we just stored the identifier field IDs as a set?

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
Expand Down
12 changes: 12 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading