-
-
Notifications
You must be signed in to change notification settings - Fork 211
[ENH] Simplified Unified Get/List API #1552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Omswastik-11
wants to merge
9
commits into
openml:main
Choose a base branch
from
Omswastik-11:prototype-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb4554f
improved the Getter API for users
Omswastik-11 990583e
rename list method to list_all
Omswastik-11 dbb13b5
update __init.py
Omswastik-11 617eada
Merge branch 'main' into prototype-api
fkiraly 5563615
Merge branch 'main' into prototype-api
Omswastik-11 169a5aa
Merge branch 'main' into prototype-api
Omswastik-11 5dd13f1
fix ci failures
Omswastik-11 decd5e4
Merge branch 'prototype-api' of https://github.com/Omswastik-11/openm…
Omswastik-11 b10eb12
move utills function to a separate dispathcer file
Omswastik-11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| """OpenML API dispatchers for unified get/list operations.""" | ||
|
|
||
| # License: BSD 3-Clause | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Callable, Dict | ||
|
|
||
| from .datasets import get_dataset, list_datasets | ||
| from .flows import get_flow, list_flows | ||
| from .runs import get_run, list_runs | ||
| from .tasks import get_task, list_tasks | ||
|
|
||
| ListDispatcher = Dict[str, Callable[..., Any]] | ||
| GetDispatcher = Dict[str, Callable[..., Any]] | ||
|
|
||
| _LIST_DISPATCH: ListDispatcher = { | ||
| "dataset": list_datasets, | ||
| "task": list_tasks, | ||
| "flow": list_flows, | ||
| "run": list_runs, | ||
| } | ||
|
|
||
| _GET_DISPATCH: GetDispatcher = { | ||
| "dataset": get_dataset, | ||
| "task": get_task, | ||
| "flow": get_flow, | ||
| "run": get_run, | ||
| } | ||
|
|
||
|
|
||
| def list_all(object_type: str, /, **kwargs: Any) -> Any: | ||
| """List OpenML objects by type (e.g., datasets, tasks, flows, runs). | ||
|
|
||
| This is a convenience dispatcher that forwards to the existing type-specific | ||
| ``list_*`` functions. Existing imports remain available for backward compatibility. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| object_type : str | ||
| The type of object to list. Must be one of 'dataset', 'task', 'flow', 'run'. | ||
| **kwargs : Any | ||
| Additional arguments passed to the underlying list function. | ||
|
|
||
| Returns | ||
| ------- | ||
| Any | ||
| The result from the type-specific list function (typically a DataFrame). | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If object_type is not one of the supported types. | ||
| """ | ||
| if not isinstance(object_type, str): | ||
| raise TypeError(f"object_type must be a string, got {type(object_type).__name__}") | ||
|
|
||
| func = _LIST_DISPATCH.get(object_type.lower()) | ||
| if func is None: | ||
| valid_types = ", ".join(repr(k) for k in _LIST_DISPATCH) | ||
| raise ValueError( | ||
| f"Unsupported object_type {object_type!r}; expected one of {valid_types}.", | ||
| ) | ||
|
|
||
| return func(**kwargs) | ||
|
|
||
|
|
||
| def get(identifier: int | str, *, object_type: str = "dataset", **kwargs: Any) -> Any: | ||
| """Get an OpenML object by identifier. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| identifier : int | str | ||
| The ID or name of the object to retrieve. | ||
| object_type : str, default="dataset" | ||
| The type of object to get. Must be one of 'dataset', 'task', 'flow', 'run'. | ||
| **kwargs : Any | ||
| Additional arguments passed to the underlying get function. | ||
|
|
||
| Returns | ||
| ------- | ||
| Any | ||
| The requested OpenML object. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If object_type is not one of the supported types. | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> openml.get(61) # Get dataset 61 (default object_type="dataset") | ||
| >>> openml.get("Fashion-MNIST") # Get dataset by name | ||
| >>> openml.get(31, object_type="task") # Get task 31 | ||
| >>> openml.get(10, object_type="flow") # Get flow 10 | ||
| >>> openml.get(20, object_type="run") # Get run 20 | ||
| """ | ||
| if not isinstance(object_type, str): | ||
| raise TypeError(f"object_type must be a string, got {type(object_type).__name__}") | ||
|
|
||
| func = _GET_DISPATCH.get(object_type.lower()) | ||
| if func is None: | ||
| valid_types = ", ".join(repr(k) for k in _GET_DISPATCH) | ||
| raise ValueError( | ||
| f"Unsupported object_type {object_type!r}; expected one of {valid_types}.", | ||
| ) | ||
|
|
||
| return func(identifier, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.