Skip to content

Commit e15e892

Browse files
committed
requested changes
1 parent 0d5ce53 commit e15e892

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

openml/_api/resources/tasks.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,9 @@ def get(
6868
return task
6969

7070
def _get_task_description(self, task_id: int) -> OpenMLTask:
71-
result = self._http.get(f"task/{task_id}", return_response=True)
71+
response = self._http.get(f"task/{task_id}", return_response=True)
7272

73-
if isinstance(result, tuple):
74-
task, _response = result
75-
else:
76-
task = result
77-
78-
return task
73+
return self._create_task_from_xml(response.text)
7974

8075
def _create_task_from_xml(self, xml: str) -> OpenMLTask:
8176
"""Create a task given a xml string.

openml/tasks/functions.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,36 @@ def get_tasks(
139139
)
140140
return tasks
141141

142+
def get_task(
143+
task_id: int,
144+
download_splits: bool = False, # noqa: FBT002
145+
**get_dataset_kwargs: Any,
146+
) -> OpenMLTask:
147+
"""Download OpenML task for a given task ID.
148+
149+
Downloads the task representation.
150+
151+
Use the `download_splits` parameter to control whether the splits are downloaded.
152+
Moreover, you may pass additional parameter (args or kwargs) that are passed to
153+
:meth:`openml.datasets.get_dataset`.
154+
155+
Parameters
156+
----------
157+
task_id : int
158+
The OpenML task id of the task to download.
159+
download_splits: bool (default=False)
160+
Whether to download the splits as well.
161+
get_dataset_kwargs :
162+
Args and kwargs can be used pass optional parameters to :meth:`openml.datasets.get_dataset`.
163+
164+
Returns
165+
-------
166+
task: OpenMLTask
167+
"""
168+
return api_context.backend.tasks.get(
169+
task_id, download_splits=download_splits, **get_dataset_kwargs
170+
)
171+
142172

143173
def create_task(
144174
task_type: TaskType,

0 commit comments

Comments
 (0)