Repository navigation
MNT: Update tests to reflect server side changes #1765
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
Changes from all commits
021fefd
e3c6c67
b6b95cd
2fb632d
434c0f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -905,6 +905,29 @@ def edit_dataset( | |
| if not isinstance(data_id, int): | ||
| raise TypeError(f"`data_id` must be of type `int`, not {type(data_id)}.") | ||
|
|
||
| if not any( | ||
| field | ||
| for field in [ | ||
| description, | ||
| creator, | ||
| contributor, | ||
| collection_date, | ||
| language, | ||
| default_target_attribute, | ||
| ignore_attribute, | ||
| citation, | ||
| row_id_attribute, | ||
| original_data_url, | ||
| paper_url, | ||
| ] | ||
| ): | ||
| raise ValueError( | ||
| "Please provide atleast one field among description, creator, " | ||
| "contributor, collection_date, language, citation, " | ||
| "original_data_url, default_target_attribute, row_id_attribute, " | ||
| "ignore_attribute or paper_url to edit.", | ||
| ) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We used to rely on the server to provide this error response, but since this behavior was even encoded into a unit test, it seems that it should rather be expected of the client to catch the error. (I think it also makes more sense - no need to do a network round trip or force work onto the server) |
||
|
|
||
| # compose data edit parameters as xml | ||
| form_data = {"data_id": data_id} # type: openml._api_calls.DATA_TYPE | ||
| xml = OrderedDict() # type: 'OrderedDict[str, OrderedDict]' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1414,32 +1414,9 @@ def test_get_dataset_cache_format_feather(self): | |
| assert len(categorical) == X.shape[1] | ||
| assert len(attribute_names) == X.shape[1] | ||
|
|
||
| @pytest.mark.test_server() | ||
| def test_data_edit_non_critical_field(self): | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After OpenML#1290 we no longer allow editing of any field by users that do not own the dataset, so this test is no longer useful. There already existed a test that asserts the handling of an authorization error when trying to modify a field the user isn't allowed to. |
||
| # Case 1 | ||
| # All users can edit non-critical fields of datasets | ||
| desc = ( | ||
| "This data sets consists of 3 different types of irises' " | ||
| "(Setosa, Versicolour, and Virginica) petal and sepal length," | ||
| " stored in a 150x4 numpy.ndarray" | ||
| ) | ||
| did = 128 | ||
| result = edit_dataset( | ||
| did, | ||
| description=desc, | ||
| creator="R.A.Fisher", | ||
| collection_date="1937", | ||
| citation="The use of multiple measurements in taxonomic problems", | ||
| language="English", | ||
| ) | ||
| assert did == result | ||
| edited_dataset = openml.datasets.get_dataset(did) | ||
| assert edited_dataset.description == desc | ||
|
|
||
| @pytest.mark.test_server() | ||
| def test_data_edit_critical_field(self): | ||
| # Case 2 | ||
| # only owners (or admin) can edit all critical fields of datasets | ||
| # only owners (or admin) can edit all fields of datasets | ||
| # for this, we need to first clone a dataset to do changes | ||
| did = fork_dataset(1) | ||
| self._wait_for_dataset_being_processed(did) | ||
|
|
@@ -1464,11 +1441,10 @@ def test_data_edit_critical_field(self): | |
| os.path.join(openml.config.get_cache_directory(), "datasets", str(did)), | ||
| ) | ||
|
|
||
| @pytest.mark.test_server() | ||
| def test_data_edit_requires_field(self): | ||
| # Check server exception when no field to edit is provided | ||
| self.assertRaisesRegex( | ||
| OpenMLServerException, | ||
| ValueError, | ||
| "Please provide atleast one field among description, creator, " | ||
| "contributor, collection_date, language, citation, " | ||
| "original_data_url, default_target_attribute, row_id_attribute, " | ||
|
|
@@ -1516,12 +1492,12 @@ def test_data_edit_cannot_edit_critical_field_if_dataset_has_task(self): | |
| ) | ||
|
|
||
| @pytest.mark.test_server() | ||
| def test_edit_data_user_cannot_edit_critical_field_of_other_users_dataset(self): | ||
| def test_edit_data_user_cannot_edit_field_of_other_users_dataset(self): | ||
| # Check server exception when a non-owner or non-admin tries to edit critical fields | ||
| self.assertRaisesRegex( | ||
| OpenMLServerException, | ||
| "Critical features default_target_attribute, row_id_attribute and ignore_attribute " | ||
| "can be edited only by the owner. Fork the dataset if changes are required.", | ||
| "Dataset can only be edited by the owner or an administrator. " | ||
| "Fork the dataset if changes are required.", | ||
| edit_dataset, | ||
| data_id=128, | ||
| default_target_attribute="y", | ||
|
|
@@ -2005,4 +1981,4 @@ def test_get_dataset_parquet(requests_mock, test_files_directory, test_server_v1 | |
| assert dataset._parquet_url is not None | ||
| assert dataset.parquet_file is not None | ||
| assert os.path.isfile(dataset.parquet_file) | ||
| assert dataset.data_file is None # is alias for arff path | ||
| assert dataset.data_file is None # is alias for arff path | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,7 @@ def test_evaluation_list_limit(self): | |
| ) | ||
| assert len(evaluations) == 100 | ||
|
|
||
| @pytest.mark.skip(reason="Affected by lowered result limit #1757") | ||
| @pytest.mark.test_server() | ||
| def test_list_evaluations_empty(self): | ||
| evaluations = openml.evaluations.list_evaluations("unexisting_measure") | ||
|
|
@@ -163,13 +164,15 @@ def test_list_evaluations_empty(self): | |
|
|
||
| assert isinstance(evaluations, dict) | ||
|
|
||
|
|
||
| @pytest.mark.production_server() | ||
| def test_evaluation_list_per_fold(self): | ||
| self.use_production_server() | ||
| size = 1000 | ||
| task_ids = [6] | ||
| uploader_ids = [1] | ||
| flow_ids = [6969] | ||
| runs = [6070667, 6070666] | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the batch limit of 1000 is fine, |
||
|
|
||
| evaluations = openml.evaluations.list_evaluations( | ||
| "predictive_accuracy", | ||
|
|
@@ -178,10 +181,11 @@ def test_evaluation_list_per_fold(self): | |
| tasks=task_ids, | ||
| flows=flow_ids, | ||
| uploaders=uploader_ids, | ||
| runs=runs, | ||
| per_fold=True, | ||
| ) | ||
|
|
||
| assert len(evaluations) == size | ||
| assert len(evaluations) == len(runs) | ||
| for run_id in evaluations: | ||
| assert evaluations[run_id].value is None | ||
| assert evaluations[run_id].values is not None | ||
|
|
@@ -195,12 +199,14 @@ def test_evaluation_list_per_fold(self): | |
| tasks=task_ids, | ||
| flows=flow_ids, | ||
| uploaders=uploader_ids, | ||
| runs=runs, | ||
| per_fold=False, | ||
| ) | ||
| for run_id in evaluations: | ||
| assert evaluations[run_id].value is not None | ||
| assert evaluations[run_id].values is None | ||
|
|
||
| @pytest.mark.skip(reason="Affected by lowered result limit #1757") | ||
| @pytest.mark.production_server() | ||
| def test_evaluation_list_sort(self): | ||
| self.use_production_server() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was made to support Python 3.10 and 3.11, which is still part of the CI matrix. When we drop support for these Python versions (which should do as soon as possible) we should revert this change.