Skip to content

Commit

Permalink
Implement Data.__eq__
Browse files Browse the repository at this point in the history
Summary: This comes handy in some tests.

Differential Revision: D54526176
  • Loading branch information
saitcakmak authored and facebook-github-bot committed Mar 5, 2024
1 parent 39c6922 commit 71cb647
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ax/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ def from_multiple_data(

return data_out

def __eq__(self, other: object) -> bool:
if not isinstance(other, Data):
return False
return self.df.equals(other.df) and self.description == other.description


def set_single_trial(data: Data) -> Data:
"""Returns a new Data object where we set all rows to have the same
Expand Down
7 changes: 7 additions & 0 deletions ax/core/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,10 @@ def test_data_column_data_types_with_extra_columns_also_deleted(self) -> None:
for c, t in Data.COLUMN_DATA_TYPES.items():
if c not in excluded_columns:
self.assertEqual(columns[c], t)

def test_equality(self) -> None:
data1 = Data(df=self.df)
data2 = Data(df=self.df)
self.assertEqual(data1, data2)
data2 = Data(df=self.df, description="data2")
self.assertNotEqual(data1, data2)

0 comments on commit 71cb647

Please sign in to comment.