diff --git a/openml/datasets/__init__.py b/openml/datasets/__init__.py index 480dd9576..7d0fa6c50 100644 --- a/openml/datasets/__init__.py +++ b/openml/datasets/__init__.py @@ -7,6 +7,7 @@ check_datasets_active, create_dataset, delete_dataset, + delete_dataset_cache, edit_dataset, fork_dataset, get_dataset, @@ -22,6 +23,7 @@ "create_dataset", "get_dataset", "get_datasets", + "delete_dataset_cache", "list_datasets", "OpenMLDataset", "OpenMLDataFeature", diff --git a/openml/datasets/functions.py b/openml/datasets/functions.py index ac5466a44..b696fce8a 100644 --- a/openml/datasets/functions.py +++ b/openml/datasets/functions.py @@ -1461,3 +1461,21 @@ def delete_dataset(dataset_id: int) -> bool: True if the deletion was successful. False otherwise. """ return openml.utils._delete_entity("data", dataset_id) + + +def delete_dataset_cache(dataset_id: int | str) -> None: + """Delete the cache directory for a specific dataset. + + Parameters + ---------- + dataset_id : int | str + Dataset ID (integer) or dataset name (string). + """ + if isinstance(dataset_id, str): + try: + dataset_id = int(dataset_id) + except ValueError: + dataset_id = _name_to_id(str(dataset_id)) + + did_cache_dir = _get_cache_dir_for_id(DATASETS_CACHE_DIR_NAME, dataset_id) + _remove_cache_dir_for_id(DATASETS_CACHE_DIR_NAME, did_cache_dir) diff --git a/openml/flows/__init__.py b/openml/flows/__init__.py index ce32fec7d..d9cf6f9df 100644 --- a/openml/flows/__init__.py +++ b/openml/flows/__init__.py @@ -4,6 +4,7 @@ from .functions import ( assert_flows_equal, delete_flow, + delete_flow_cache, flow_exists, get_flow, get_flow_id, @@ -13,6 +14,7 @@ __all__ = [ "OpenMLFlow", "get_flow", + "delete_flow_cache", "list_flows", "get_flow_id", "flow_exists", diff --git a/openml/flows/functions.py b/openml/flows/functions.py index 9906958e5..b5bb1130c 100644 --- a/openml/flows/functions.py +++ b/openml/flows/functions.py @@ -552,3 +552,21 @@ def delete_flow(flow_id: int) -> bool: True if the deletion was successful. False otherwise. """ return openml.utils._delete_entity("flow", flow_id) + + +def delete_flow_cache(flow_id: int) -> None: + """Delete the cache directory for a specific flow. + + Parameters + ---------- + flow_id : int + Flow ID (integer). + """ + if isinstance(flow_id, str): + try: + flow_id = int(flow_id) + except ValueError: + raise ValueError("Flow ID should be an integer") from None + + fid_cache_dir = openml.utils._create_cache_directory_for_id(FLOWS_CACHE_DIR_NAME, flow_id) + openml.utils._remove_cache_dir_for_id(FLOWS_CACHE_DIR_NAME, fid_cache_dir) diff --git a/openml/runs/__init__.py b/openml/runs/__init__.py index 6d3dca504..329093050 100644 --- a/openml/runs/__init__.py +++ b/openml/runs/__init__.py @@ -2,6 +2,7 @@ from .functions import ( delete_run, + delete_run_cache, get_run, get_run_trace, get_runs, @@ -22,6 +23,7 @@ "run_model_on_task", "run_flow_on_task", "get_run", + "delete_run_cache", "list_runs", "get_runs", "get_run_trace", diff --git a/openml/runs/functions.py b/openml/runs/functions.py index 666b75c37..f47b9cb3e 100644 --- a/openml/runs/functions.py +++ b/openml/runs/functions.py @@ -1301,3 +1301,21 @@ def delete_run(run_id: int) -> bool: True if the deletion was successful. False otherwise. """ return openml.utils._delete_entity("run", run_id) + + +def delete_run_cache(run_id: int) -> None: + """Delete the cache directory for a specific run. + + Parameters + ---------- + run_id : int + Run ID (integer). + """ + if isinstance(run_id, str): + try: + run_id = int(run_id) + except ValueError: + raise ValueError("Run ID should be an integer") from None + + run_cache_dir = openml.utils._create_cache_directory_for_id(RUNS_CACHE_DIR_NAME, run_id) + openml.utils._remove_cache_dir_for_id(RUNS_CACHE_DIR_NAME, run_cache_dir) diff --git a/openml/tasks/__init__.py b/openml/tasks/__init__.py index f6df3a8d4..309672c84 100644 --- a/openml/tasks/__init__.py +++ b/openml/tasks/__init__.py @@ -3,6 +3,7 @@ from .functions import ( create_task, delete_task, + delete_task_cache, get_task, get_tasks, list_tasks, @@ -28,6 +29,7 @@ "create_task", "get_task", "get_tasks", + "delete_task_cache", "list_tasks", "OpenMLSplit", "TaskType", diff --git a/openml/tasks/functions.py b/openml/tasks/functions.py index d2bf5e946..1d5c77ee8 100644 --- a/openml/tasks/functions.py +++ b/openml/tasks/functions.py @@ -612,3 +612,21 @@ def delete_task(task_id: int) -> bool: True if the deletion was successful. False otherwise. """ return openml.utils._delete_entity("task", task_id) + + +def delete_task_cache(task_id: int) -> None: + """Delete the cache directory for a specific task. + + Parameters + ---------- + task_id : int + Task ID (integer). + """ + if isinstance(task_id, str): + try: + task_id = int(task_id) + except ValueError: + raise ValueError("Task ID should be an integer") from None + + tid_cache_dir = openml.utils._create_cache_directory_for_id(TASKS_CACHE_DIR_NAME, task_id) + openml.utils._remove_cache_dir_for_id(TASKS_CACHE_DIR_NAME, tid_cache_dir)