Skip to content

Commit ad341d2

Browse files
AndreyMarkinPPCGerrit Code Review
authored andcommitted
Merge "[gaarf-py] Reports with same data but different order should be equal" into main
2 parents 2942dbc + 7160c0b commit ad341d2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

py/gaarf/report.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,12 @@ def _get_columns_slice(self, key: str | MutableSequence[str]) -> GaarfReport:
355355
def __eq__(self, other) -> bool:
356356
if not isinstance(other, self.__class__):
357357
return False
358-
if self.column_names != other.column_names:
358+
if sorted(self.column_names) != sorted(other.column_names):
359359
return False
360-
return self.results == other.results
360+
for self_row, other_row in zip(self, other):
361+
if self_row.to_dict() != other_row.to_dict():
362+
return False
363+
return True
361364

362365
def __add__(self, other: GaarfReport) -> GaarfReport:
363366
"""Combines two reports into one.

py/tests/unit/test_report.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ def test_report_with_same_data_are_equal(self, multi_column_report):
456456
)
457457
assert new_multi_column_report == multi_column_report
458458

459+
def test_report_with_same_data_different_order_are_equal(
460+
self, multi_column_report
461+
):
462+
new_multi_column_report = report.GaarfReport(
463+
results=[[2, 1], [3, 2], [4, 3]],
464+
column_names=['ad_group_id', 'campaign_id'],
465+
)
466+
assert new_multi_column_report == multi_column_report
467+
459468

460469
class TestGaarfRow:
461470
@pytest.fixture

0 commit comments

Comments
 (0)