diff --git a/openml/_api_calls.py b/openml/_api_calls.py index 81a3d7756..93f0ed2f1 100644 --- a/openml/_api_calls.py +++ b/openml/_api_calls.py @@ -139,9 +139,9 @@ def _parse_server_exception(response, url=None): additional = None if 'oml:additional_information' in server_exception['oml:error']: additional = server_exception['oml:error']['oml:additional_information'] - if code in [370, 372, 512, 500, 482]: - # 512 for runs, 370 for datasets (should be 372), 500 for flows - # 482 for tasks + if code in [372, 512, 500, 482, 542, 674]: # datasets, + # 512 for runs, 372 for datasets, 500 for flows + # 482 for tasks, 542 for evaluations, 674 for setups return OpenMLServerNoResult(code, message, additional) return OpenMLServerException( code=code, diff --git a/openml/datasets/functions.py b/openml/datasets/functions.py index a586090d4..b9a1079be 100644 --- a/openml/datasets/functions.py +++ b/openml/datasets/functions.py @@ -189,7 +189,7 @@ def _list_datasets(api_call): try: xml_string = _perform_api_call(api_call) except OpenMLServerNoResult: - return [] + return dict() datasets_dict = xmltodict.parse(xml_string, force_list=('oml:dataset',)) # Minimalistic check if the XML is useful diff --git a/openml/evaluations/functions.py b/openml/evaluations/functions.py index aa7f86635..c3e0d9914 100644 --- a/openml/evaluations/functions.py +++ b/openml/evaluations/functions.py @@ -1,5 +1,6 @@ import xmltodict +from openml.exceptions import OpenMLServerNoResult from .._api_calls import _perform_api_call from ..evaluations import OpenMLEvaluation @@ -59,8 +60,10 @@ def list_evaluations(function, offset=None, size=None, id=None, task=None, def _list_evaluations(api_call): """Helper function to parse API calls which are lists of runs""" - - xml_string = _perform_api_call(api_call) + try: + xml_string = _perform_api_call(api_call) + except OpenMLServerNoResult: + return dict() evals_dict = xmltodict.parse(xml_string, force_list=('oml:evaluation',)) # Minimalistic check if the XML is useful diff --git a/openml/flows/functions.py b/openml/flows/functions.py index bd8467a42..61a260f35 100644 --- a/openml/flows/functions.py +++ b/openml/flows/functions.py @@ -112,7 +112,7 @@ def _list_flows(api_call): try: xml_string = _perform_api_call(api_call) except OpenMLServerNoResult: - return [] + return dict() flows_dict = xmltodict.parse(xml_string, force_list=('oml:flow',)) # Minimalistic check if the XML is useful diff --git a/openml/runs/functions.py b/openml/runs/functions.py index 6a4292b36..8a28fa528 100644 --- a/openml/runs/functions.py +++ b/openml/runs/functions.py @@ -948,7 +948,7 @@ def _list_runs(api_call): try: xml_string = _perform_api_call(api_call) except OpenMLServerNoResult: - return [] + return dict() runs_dict = xmltodict.parse(xml_string, force_list=('oml:run',)) # Minimalistic check if the XML is useful diff --git a/openml/setups/functions.py b/openml/setups/functions.py index c0e256607..a78e07ae6 100644 --- a/openml/setups/functions.py +++ b/openml/setups/functions.py @@ -8,6 +8,7 @@ from .. import config from .setup import OpenMLSetup, OpenMLParameter from openml.flows import flow_exists +from openml.exceptions import OpenMLServerNoResult def setup_exists(flow, model=None): @@ -145,7 +146,10 @@ def list_setups(flow=None, tag=None, setup=None, offset=None, size=None): def _list_setups(api_call): """Helper function to parse API calls which are lists of setups""" - xml_string = openml._api_calls._perform_api_call(api_call) + try: + xml_string = openml._api_calls._perform_api_call(api_call) + except OpenMLServerNoResult: + return dict() setups_dict = xmltodict.parse(xml_string, force_list=('oml:setup',)) # Minimalistic check if the XML is useful diff --git a/openml/study/functions.py b/openml/study/functions.py index 11c47d674..535cf8dcd 100644 --- a/openml/study/functions.py +++ b/openml/study/functions.py @@ -3,6 +3,7 @@ from openml.study import OpenMLStudy from .._api_calls import _perform_api_call + def _multitag_to_list(result_dict, tag): if isinstance(result_dict[tag], list): return result_dict[tag] diff --git a/openml/tasks/functions.py b/openml/tasks/functions.py index 31a76eb48..32c4c0fec 100644 --- a/openml/tasks/functions.py +++ b/openml/tasks/functions.py @@ -141,7 +141,7 @@ def _list_tasks(api_call): try: xml_string = _perform_api_call(api_call) except OpenMLServerNoResult: - return [] + return dict() tasks_dict = xmltodict.parse(xml_string, force_list=('oml:task','oml:input')) # Minimalistic check if the XML is useful if 'oml:tasks' not in tasks_dict: diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index 35db14ec0..0f55b503d 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -147,6 +147,14 @@ def test_list_datasets_paginate(self): for did in datasets: self._check_dataset(datasets[did]) + def test_list_datasets_empty(self): + datasets = openml.datasets.list_datasets(tag='NoOneWouldUseThisTagAnyway') + if len(datasets) > 0: + raise ValueError('UnitTest Outdated, tag was already used (please remove)') + + self.assertIsInstance(datasets, dict) + + @unittest.skip('See https://github.com/openml/openml-python/issues/149') def test_check_datasets_active(self): active = openml.datasets.check_datasets_active([1, 17]) diff --git a/tests/test_evaluations/test_evaluation_functions.py b/tests/test_evaluations/test_evaluation_functions.py index 47e6d72e4..771ee2cd4 100644 --- a/tests/test_evaluations/test_evaluation_functions.py +++ b/tests/test_evaluations/test_evaluation_functions.py @@ -63,3 +63,10 @@ def test_evaluation_list_limit(self): evaluations = openml.evaluations.list_evaluations("predictive_accuracy", size=100, offset=100) self.assertEquals(len(evaluations), 100) + + def test_list_evaluations_empty(self): + evaluations = openml.evaluations.list_evaluations('unexisting_measure') + if len(evaluations) > 0: + raise ValueError('UnitTest Outdated, got somehow results') + + self.assertIsInstance(evaluations, dict) \ No newline at end of file diff --git a/tests/test_flows/test_flow_functions.py b/tests/test_flows/test_flow_functions.py index 47e04581b..419b86f13 100644 --- a/tests/test_flows/test_flow_functions.py +++ b/tests/test_flows/test_flow_functions.py @@ -31,6 +31,13 @@ def test_list_flows(self): for fid in flows: self._check_flow(flows[fid]) + def test_list_flows_empty(self): + flows = openml.flows.list_flows(tag='NoOneEverUsesThisTag123') + if len(flows) > 0: + raise ValueError('UnitTest Outdated, got somehow results (please adapt)') + + self.assertIsInstance(flows, dict) + def test_list_flows_by_tag(self): flows = openml.flows.list_flows(tag='weka') self.assertGreaterEqual(len(flows), 5) diff --git a/tests/test_runs/test_run_functions.py b/tests/test_runs/test_run_functions.py index e2fd5b286..56abdd266 100644 --- a/tests/test_runs/test_run_functions.py +++ b/tests/test_runs/test_run_functions.py @@ -830,6 +830,13 @@ def test_get_runs_list(self): for rid in runs: self._check_run(runs[rid]) + def test_list_runs_empty(self): + runs = openml.runs.list_runs(task=[-1]) + if len(runs) > 0: + raise ValueError('UnitTest Outdated, got somehow results') + + self.assertIsInstance(runs, dict) + def test_get_runs_list_by_task(self): # TODO: comes from live, no such lists on test openml.config.server = self.production_server diff --git a/tests/test_setups/test_setup_functions.py b/tests/test_setups/test_setup_functions.py index 85cb8419f..9dffe5a04 100644 --- a/tests/test_setups/test_setup_functions.py +++ b/tests/test_setups/test_setup_functions.py @@ -137,6 +137,13 @@ def test_setup_list_filter_flow(self): for setup_id in setups.keys(): self.assertEquals(setups[setup_id].flow_id, flow_id) + def test_list_setups_empty(self): + setups = openml.setups.list_setups(setup=[-1]) + if len(setups) > 0: + raise ValueError('UnitTest Outdated, got somehow results') + + self.assertIsInstance(setups, dict) + def test_setuplist_offset(self): # TODO: remove after pull on live for better testing # openml.config.server = self.production_server diff --git a/tests/test_tasks/test_task_functions.py b/tests/test_tasks/test_task_functions.py index ea84a27c7..21cc9c0e2 100644 --- a/tests/test_tasks/test_task_functions.py +++ b/tests/test_tasks/test_task_functions.py @@ -67,6 +67,13 @@ def test_list_tasks_by_type(self): self.assertEquals(ttid, tasks[tid]["ttid"]) self._check_task(tasks[tid]) + def test_list_tasks_empty(self): + tasks = openml.tasks.list_tasks(tag='NoOneWillEverUseThisTag') + if len(tasks) > 0: + raise ValueError('UnitTest Outdated, got somehow results (tag is used, please adapt)') + + self.assertIsInstance(tasks, dict) + def test_list_tasks_by_tag(self): num_basic_tasks = 100 # number is flexible, check server if fails tasks = openml.tasks.list_tasks(tag='study_14')