Skip to content

Commit edc5772

Browse files
committed
added tag and untag methods
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
1 parent 6e577c4 commit edc5772

3 files changed

Lines changed: 37 additions & 21 deletions

File tree

openml/_api/resources/flows.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,6 @@ def publish(self, path: str | None = None, files: Mapping[str, Any] | None = Non
152152
path = "flow"
153153
return super().publish(path, files)
154154

155-
def delete(self, flow_id: int) -> bool:
156-
"""Delete a flow from the OpenML server.
157-
158-
Parameters
159-
----------
160-
flow_id : int
161-
The ID of the flow to delete.
162-
"""
163-
return super().delete(flow_id)
164-
165155

166156
class FlowsV2(ResourceV2, FlowsAPI):
167157
def get(
@@ -221,18 +211,15 @@ def exists(self, name: str, external_version: str) -> int | bool:
221211
def list(
222212
self,
223213
*,
224-
limit: int | None = None,
225-
offset: int | None = None,
226-
tag: str | None = None,
227-
uploader: str | None = None,
214+
limit: int | None = None, # noqa: ARG002
215+
offset: int | None = None, # noqa: ARG002
216+
tag: str | None = None, # noqa: ARG002
217+
uploader: str | None = None, # noqa: ARG002
228218
) -> pd.DataFrame:
229-
raise NotImplementedError("flows (list) not yet implemented in v2 server")
230-
231-
def publish(self, flow: OpenMLFlow) -> OpenMLFlow: # type: ignore[override]
232-
raise NotImplementedError("POST /flows (create) not yet implemented in v2 server")
219+
self._not_supported(method="list")
233220

234-
def delete(self, flow_id: int) -> bool:
235-
raise NotImplementedError("DELETE /flows/{id} not yet implemented in v2 server")
221+
def publish(self, path: str | None = None, files: Mapping[str, Any] | None = None) -> int: # type: ignore[override] # noqa: ARG002
222+
self._not_supported(method="publish")
236223

237224
@staticmethod
238225
def _convert_v2_to_v1_format(v2_json: dict[str, Any]) -> dict[str, dict]:

openml/flows/flow.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ def publish(self, raise_error_if_exists: bool = False) -> OpenMLFlow: # noqa: F
444444
if "description" not in file_elements:
445445
file_elements["description"] = self._to_xml()
446446

447+
# Use api_context.backend.flows.publish which internally calls ResourceV1.publish
447448
flow_id = api_context.backend.flows.publish(path="flow", files=file_elements)
448449
self.flow_id = flow_id
449450
elif raise_error_if_exists:
@@ -473,6 +474,34 @@ def publish(self, raise_error_if_exists: bool = False) -> OpenMLFlow: # noqa: F
473474
) from e
474475
return self
475476

477+
def push_tag(self, tag: str) -> None:
478+
"""Annotates this flow with a tag on the server.
479+
480+
Parameters
481+
----------
482+
tag : str
483+
Tag to attach to the flow.
484+
"""
485+
from openml._api import api_context
486+
487+
if self.flow_id is None:
488+
raise ValueError("Flow does not have an ID. Please publish the flow before tagging.")
489+
api_context.backend.flows.tag(self.flow_id, tag)
490+
491+
def remove_tag(self, tag: str) -> None:
492+
"""Removes a tag from this flow on the server.
493+
494+
Parameters
495+
----------
496+
tag : str
497+
Tag to remove from the flow.
498+
"""
499+
from openml._api import api_context
500+
501+
if self.flow_id is None:
502+
raise ValueError("Flow does not have an ID. Please publish the flow before untagging.")
503+
api_context.backend.flows.untag(self.flow_id, tag)
504+
476505
def get_structure(self, key_item: str) -> dict[str, list[str]]:
477506
"""
478507
Returns for each sub-component of the flow the path of identifiers

openml/flows/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _get_cached_flow(fid: int) -> OpenMLFlow:
6969
raise OpenMLCacheException(f"Flow file for fid {fid} not cached") from e
7070

7171

72-
# @openml.utils.thread_safe_if_oslo_installed
72+
@openml.utils.thread_safe_if_oslo_installed
7373
def get_flow(flow_id: int, reinstantiate: bool = False, strict_version: bool = True) -> OpenMLFlow: # noqa: FBT002
7474
"""Download the OpenML flow for a given flow ID.
7575

0 commit comments

Comments
 (0)