diff --git a/openml/tasks/functions.py b/openml/tasks/functions.py index 4c0aeaf4a..c44d55ea7 100644 --- a/openml/tasks/functions.py +++ b/openml/tasks/functions.py @@ -90,7 +90,7 @@ def _get_estimation_procedure_list(): procs_dict = xmltodict.parse(xml_string) # Minimalistic check if the XML is useful if "oml:estimationprocedures" not in procs_dict: - raise ValueError("Error in return XML, does not contain tag " "oml:estimationprocedures.") + raise ValueError("Error in return XML, does not contain tag oml:estimationprocedures.") elif "@xmlns:oml" not in procs_dict["oml:estimationprocedures"]: raise ValueError( "Error in return XML, does not contain tag " @@ -106,10 +106,19 @@ def _get_estimation_procedure_list(): procs = [] for proc_ in procs_dict["oml:estimationprocedures"]["oml:estimationprocedure"]: + task_type_int = int(proc_["oml:ttid"]) + try: + task_type_id = TaskType(task_type_int) + except ValueError as e: + warnings.warn( + f"Could not create task type id for {task_type_int} due to error {e}", + RuntimeWarning, + ) + continue procs.append( { "id": int(proc_["oml:id"]), - "task_type_id": TaskType(int(proc_["oml:ttid"])), + "task_type_id": task_type_id, "name": proc_["oml:name"], "type": proc_["oml:type"], } @@ -124,7 +133,7 @@ def list_tasks( size: Optional[int] = None, tag: Optional[str] = None, output_format: str = "dict", - **kwargs + **kwargs, ) -> Union[Dict, pd.DataFrame]: """ Return a number of tasks having the given tag and task_type @@ -175,7 +184,7 @@ def list_tasks( offset=offset, size=size, tag=tag, - **kwargs + **kwargs, ) @@ -240,9 +249,18 @@ def __list_tasks(api_call, output_format="dict"): tid = None try: tid = int(task_["oml:task_id"]) + task_type_int = int(task_["oml:task_type_id"]) + try: + task_type_id = TaskType(task_type_int) + except ValueError as e: + warnings.warn( + f"Could not create task type id for {task_type_int} due to error {e}", + RuntimeWarning, + ) + continue task = { "tid": tid, - "ttid": TaskType(int(task_["oml:task_type_id"])), + "ttid": task_type_id, "did": int(task_["oml:did"]), "name": task_["oml:name"], "task_type": task_["oml:task_type"], @@ -330,7 +348,10 @@ def get_task( task """ if not isinstance(task_id, int): - warnings.warn("Task id must be specified as `int` from 0.14.0 onwards.", DeprecationWarning) + warnings.warn( + "Task id must be specified as `int` from 0.14.0 onwards.", + DeprecationWarning, + ) try: task_id = int(task_id) @@ -466,9 +487,12 @@ def create_task( estimation_procedure_id: int, target_name: Optional[str] = None, evaluation_measure: Optional[str] = None, - **kwargs + **kwargs, ) -> Union[ - OpenMLClassificationTask, OpenMLRegressionTask, OpenMLLearningCurveTask, OpenMLClusteringTask + OpenMLClassificationTask, + OpenMLRegressionTask, + OpenMLLearningCurveTask, + OpenMLClusteringTask, ]: """Create a task based on different given attributes. @@ -519,5 +543,5 @@ def create_task( target_name=target_name, estimation_procedure_id=estimation_procedure_id, evaluation_measure=evaluation_measure, - **kwargs + **kwargs, )