Skip to content

Commit

Permalink
add: test for dataset comparison and ignore fields (#1370)
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartPurucker authored Oct 16, 2024
1 parent 82d8ffa commit 8fbf39e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions openml/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,26 @@ def __eq__(self, other: Any) -> bool:
"version",
"upload_date",
"url",
"_parquet_url",
"dataset",
"data_file",
"format",
"cache_format",
}

cache_fields = {
"_dataset",
"data_file",
"data_pickle_file",
"data_feather_file",
"feather_attribute_file",
"parquet_file",
}

# check that common keys and values are identical
self_keys = set(self.__dict__.keys()) - server_fields
other_keys = set(other.__dict__.keys()) - server_fields
ignore_fields = server_fields | cache_fields
self_keys = set(self.__dict__.keys()) - ignore_fields
other_keys = set(other.__dict__.keys()) - ignore_fields
return self_keys == other_keys and all(
self.__dict__[key] == other.__dict__[key] for key in self_keys
)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_datasets/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ def test_lazy_loading_metadata(self):
assert _dataset.features == _compare_dataset.features
assert _dataset.qualities == _compare_dataset.qualities

def test_equality_comparison(self):
self.assertEqual(self.iris, self.iris)
self.assertNotEqual(self.iris, self.titanic)
self.assertNotEqual(self.titanic, 'Wrong_object')

class OpenMLDatasetTestOnTestServer(TestBase):
def setUp(self):
Expand Down

0 comments on commit 8fbf39e

Please sign in to comment.