Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: test for dataset comparison and ignore fields #1370

Merged
merged 2 commits into from
Oct 16, 2024
Merged
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
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
Loading