diff --git a/openml/datasets/dataset.py b/openml/datasets/dataset.py index bde633432..60074d1ec 100644 --- a/openml/datasets/dataset.py +++ b/openml/datasets/dataset.py @@ -16,6 +16,7 @@ import openml._api_calls from .data_feature import OpenMLDataFeature from ..exceptions import PyOpenMLError +from ..utils import _tag_entity logger = logging.getLogger(__name__) @@ -284,8 +285,7 @@ def push_tag(self, tag): tag : str Tag to attach to the dataset. """ - data = {'data_id': self.dataset_id, 'tag': tag} - openml._api_calls._perform_api_call("/data/tag", 'post', data=data) + _tag_entity('data', self.dataset_id, tag) def remove_tag(self, tag): """Removes a tag from this dataset on the server. @@ -295,8 +295,7 @@ def remove_tag(self, tag): tag : str Tag to attach to the dataset. """ - data = {'data_id': self.dataset_id, 'tag': tag} - openml._api_calls._perform_api_call("/data/untag", 'post', data=data) + _tag_entity('data', self.dataset_id, tag, untag=True) def __eq__(self, other): diff --git a/openml/flows/flow.py b/openml/flows/flow.py index 348f276be..1ab8d12d0 100644 --- a/openml/flows/flow.py +++ b/openml/flows/flow.py @@ -4,10 +4,8 @@ import xmltodict -import openml._api_calls -import openml.exceptions from ..extensions import get_extension_by_flow -from ..utils import extract_xml_tags +from ..utils import extract_xml_tags, _tag_entity class OpenMLFlow(object): @@ -455,8 +453,7 @@ def push_tag(self, tag): tag : str Tag to attach to the flow. """ - data = {'flow_id': self.flow_id, 'tag': tag} - openml._api_calls._perform_api_call("/flow/tag", 'post', data=data) + _tag_entity('flow', self.flow_id, tag) def remove_tag(self, tag): """Removes a tag from this flow on the server. @@ -466,8 +463,7 @@ def remove_tag(self, tag): tag : str Tag to attach to the flow. """ - data = {'flow_id': self.flow_id, 'tag': tag} - openml._api_calls._perform_api_call("/flow/untag", 'post', data=data) + _tag_entity('flow', self.flow_id, tag, untag=True) def _copy_server_fields(source_flow, target_flow): diff --git a/openml/runs/run.py b/openml/runs/run.py index 821f8ed48..f718384dd 100644 --- a/openml/runs/run.py +++ b/openml/runs/run.py @@ -1,7 +1,7 @@ from collections import OrderedDict import pickle import time -from typing import Any, IO, Optional, TextIO, TYPE_CHECKING # noqa: F401 +from typing import Any, IO, TextIO import os import arff @@ -13,6 +13,7 @@ from ..exceptions import PyOpenMLError from ..flows import get_flow from ..tasks import get_task, TaskTypeEnum +from ..utils import _tag_entity class OpenMLRun(object): @@ -468,8 +469,7 @@ def push_tag(self, tag): tag : str Tag to attach to the run. """ - data = {'run_id': self.run_id, 'tag': tag} - openml._api_calls._perform_api_call("/run/tag", 'post', data=data) + _tag_entity('run', self.run_id, tag) def remove_tag(self, tag): """Removes a tag from this run on the server. @@ -479,8 +479,7 @@ def remove_tag(self, tag): tag : str Tag to attach to the run. """ - data = {'run_id': self.run_id, 'tag': tag} - openml._api_calls._perform_api_call("/run/untag", 'post', data=data) + _tag_entity('run', self.run_id, tag, untag=True) ############################################################################### diff --git a/openml/tasks/task.py b/openml/tasks/task.py index c3ae36b10..7479bf36c 100644 --- a/openml/tasks/task.py +++ b/openml/tasks/task.py @@ -4,7 +4,7 @@ from .. import datasets from .split import OpenMLSplit import openml._api_calls -from ..utils import _create_cache_directory_for_id +from ..utils import _create_cache_directory_for_id, _tag_entity class OpenMLTask(object): @@ -76,8 +76,7 @@ def push_tag(self, tag): tag : str Tag to attach to the task. """ - data = {'task_id': self.task_id, 'tag': tag} - openml._api_calls._perform_api_call("/task/tag", 'post', data=data) + _tag_entity('task', self.task_id, tag) def remove_tag(self, tag): """Removes a tag from this task on the server. @@ -87,8 +86,7 @@ def remove_tag(self, tag): tag : str Tag to attach to the task. """ - data = {'task_id': self.task_id, 'tag': tag} - openml._api_calls._perform_api_call("/task/untag", 'post', data=data) + _tag_entity('task', self.task_id, tag, untag=True) class OpenMLSupervisedTask(OpenMLTask):