Skip to content

Commit 8cc1436

Browse files
sahithyaravimfeurer
authored andcommitted
add tag_entity as backend (#667)
* add tag_entity as backend * removed unused import * fix pyflakes errors * remove trailing space * fix mypy error
1 parent 3dc6dee commit 8cc1436

4 files changed

Lines changed: 13 additions & 21 deletions

File tree

openml/datasets/dataset.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import openml._api_calls
1717
from .data_feature import OpenMLDataFeature
1818
from ..exceptions import PyOpenMLError
19+
from ..utils import _tag_entity
1920

2021

2122
logger = logging.getLogger(__name__)
@@ -284,8 +285,7 @@ def push_tag(self, tag):
284285
tag : str
285286
Tag to attach to the dataset.
286287
"""
287-
data = {'data_id': self.dataset_id, 'tag': tag}
288-
openml._api_calls._perform_api_call("/data/tag", 'post', data=data)
288+
_tag_entity('data', self.dataset_id, tag)
289289

290290
def remove_tag(self, tag):
291291
"""Removes a tag from this dataset on the server.
@@ -295,8 +295,7 @@ def remove_tag(self, tag):
295295
tag : str
296296
Tag to attach to the dataset.
297297
"""
298-
data = {'data_id': self.dataset_id, 'tag': tag}
299-
openml._api_calls._perform_api_call("/data/untag", 'post', data=data)
298+
_tag_entity('data', self.dataset_id, tag, untag=True)
300299

301300
def __eq__(self, other):
302301

openml/flows/flow.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
import xmltodict
66

7-
import openml._api_calls
8-
import openml.exceptions
97
from ..extensions import get_extension_by_flow
10-
from ..utils import extract_xml_tags
8+
from ..utils import extract_xml_tags, _tag_entity
119

1210

1311
class OpenMLFlow(object):
@@ -455,8 +453,7 @@ def push_tag(self, tag):
455453
tag : str
456454
Tag to attach to the flow.
457455
"""
458-
data = {'flow_id': self.flow_id, 'tag': tag}
459-
openml._api_calls._perform_api_call("/flow/tag", 'post', data=data)
456+
_tag_entity('flow', self.flow_id, tag)
460457

461458
def remove_tag(self, tag):
462459
"""Removes a tag from this flow on the server.
@@ -466,8 +463,7 @@ def remove_tag(self, tag):
466463
tag : str
467464
Tag to attach to the flow.
468465
"""
469-
data = {'flow_id': self.flow_id, 'tag': tag}
470-
openml._api_calls._perform_api_call("/flow/untag", 'post', data=data)
466+
_tag_entity('flow', self.flow_id, tag, untag=True)
471467

472468

473469
def _copy_server_fields(source_flow, target_flow):

openml/runs/run.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import OrderedDict
22
import pickle
33
import time
4-
from typing import Any, IO, Optional, TextIO, TYPE_CHECKING # noqa: F401
4+
from typing import Any, IO, TextIO
55
import os
66

77
import arff
@@ -13,6 +13,7 @@
1313
from ..exceptions import PyOpenMLError
1414
from ..flows import get_flow
1515
from ..tasks import get_task, TaskTypeEnum
16+
from ..utils import _tag_entity
1617

1718

1819
class OpenMLRun(object):
@@ -468,8 +469,7 @@ def push_tag(self, tag):
468469
tag : str
469470
Tag to attach to the run.
470471
"""
471-
data = {'run_id': self.run_id, 'tag': tag}
472-
openml._api_calls._perform_api_call("/run/tag", 'post', data=data)
472+
_tag_entity('run', self.run_id, tag)
473473

474474
def remove_tag(self, tag):
475475
"""Removes a tag from this run on the server.
@@ -479,8 +479,7 @@ def remove_tag(self, tag):
479479
tag : str
480480
Tag to attach to the run.
481481
"""
482-
data = {'run_id': self.run_id, 'tag': tag}
483-
openml._api_calls._perform_api_call("/run/untag", 'post', data=data)
482+
_tag_entity('run', self.run_id, tag, untag=True)
484483

485484

486485
###############################################################################

openml/tasks/task.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .. import datasets
55
from .split import OpenMLSplit
66
import openml._api_calls
7-
from ..utils import _create_cache_directory_for_id
7+
from ..utils import _create_cache_directory_for_id, _tag_entity
88

99

1010
class OpenMLTask(object):
@@ -76,8 +76,7 @@ def push_tag(self, tag):
7676
tag : str
7777
Tag to attach to the task.
7878
"""
79-
data = {'task_id': self.task_id, 'tag': tag}
80-
openml._api_calls._perform_api_call("/task/tag", 'post', data=data)
79+
_tag_entity('task', self.task_id, tag)
8180

8281
def remove_tag(self, tag):
8382
"""Removes a tag from this task on the server.
@@ -87,8 +86,7 @@ def remove_tag(self, tag):
8786
tag : str
8887
Tag to attach to the task.
8988
"""
90-
data = {'task_id': self.task_id, 'tag': tag}
91-
openml._api_calls._perform_api_call("/task/untag", 'post', data=data)
89+
_tag_entity('task', self.task_id, tag, untag=True)
9290

9391

9492
class OpenMLSupervisedTask(OpenMLTask):

0 commit comments

Comments
 (0)