Skip to content

Commit f62f606

Browse files
authored
Merge branch 'main' into flow-migration-stacked
2 parents eb26cd4 + dc1b22a commit f62f606

6 files changed

Lines changed: 64 additions & 13 deletions

File tree

examples/Advanced/tasks_tutorial.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
#
2525
# We will start by simply listing only *supervised classification* tasks.
2626
#
27-
# **openml.tasks.list_tasks()** returns a dictionary of dictionaries by default, but we
28-
# request a
27+
# **openml.list_tasks()** (or **openml.tasks.list_tasks()**) returns a dictionary of dictionaries by default, but we request a
2928
# [pandas dataframe](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html)
3029
# instead to have better visualization capabilities and easier access:
3130

3231
# %%
33-
tasks = openml.tasks.list_tasks(task_type=TaskType.SUPERVISED_CLASSIFICATION)
32+
# New: top-level convenience alias
33+
tasks = openml.list_tasks(task_type=TaskType.SUPERVISED_CLASSIFICATION)
34+
# Old path still works:
35+
# tasks = openml.tasks.list_tasks(task_type=TaskType.SUPERVISED_CLASSIFICATION)
3436
print(tasks.columns)
3537
print(f"First 5 of {len(tasks)} tasks:")
3638
print(tasks.head())
@@ -66,23 +68,29 @@
6668
# Similar to listing tasks by task type, we can list tasks by tags:
6769

6870
# %%
69-
tasks = openml.tasks.list_tasks(tag="OpenML100")
71+
tasks = openml.list_tasks(tag="OpenML100")
72+
# Old path still works:
73+
# tasks = openml.tasks.list_tasks(tag="OpenML100")
7074
print(f"First 5 of {len(tasks)} tasks:")
7175
print(tasks.head())
7276

7377
# %% [markdown]
7478
# Furthermore, we can list tasks based on the dataset id:
7579

7680
# %%
77-
tasks = openml.tasks.list_tasks(data_id=1471)
81+
tasks = openml.list_tasks(data_id=1471)
82+
# Old path still works:
83+
# tasks = openml.tasks.list_tasks(data_id=1471)
7884
print(f"First 5 of {len(tasks)} tasks:")
7985
print(tasks.head())
8086

8187
# %% [markdown]
8288
# In addition, a size limit and an offset can be applied both separately and simultaneously:
8389

8490
# %%
85-
tasks = openml.tasks.list_tasks(size=10, offset=50)
91+
tasks = openml.list_tasks(size=10, offset=50)
92+
# Old path still works:
93+
# tasks = openml.tasks.list_tasks(size=10, offset=50)
8694
print(tasks)
8795

8896
# %% [markdown]
@@ -98,7 +106,9 @@
98106
# Finally, it is also possible to list all tasks on OpenML with:
99107

100108
# %%
101-
tasks = openml.tasks.list_tasks()
109+
tasks = openml.list_tasks()
110+
# Old path still works:
111+
# tasks = openml.tasks.list_tasks()
102112
print(len(tasks))
103113

104114
# %% [markdown]
@@ -118,7 +128,10 @@
118128

119129
# %%
120130
task_id = 31
121-
task = openml.tasks.get_task(task_id)
131+
# New: top-level convenience alias
132+
task = openml.get_task(task_id)
133+
# Old path still works:
134+
# task = openml.tasks.get_task(task_id)
122135

123136
# %%
124137
# Properties of the task are stored as member variables:

examples/Basics/simple_datasets_tutorial.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@
1414
# ## List datasets stored on OpenML
1515

1616
# %%
17-
datasets_df = openml.datasets.list_datasets()
17+
# New: top-level convenience alias
18+
datasets_df = openml.list_datasets()
19+
# Old path still works for backwards compatibility:
20+
# datasets_df = openml.datasets.list_datasets()
1821
print(datasets_df.head(n=10))
1922

2023
# %% [markdown]
2124
# ## Download a dataset
2225

2326
# %%
2427
# Iris dataset https://www.openml.org/d/61
25-
dataset = openml.datasets.get_dataset(dataset_id=61)
28+
# New: top-level convenience alias
29+
dataset = openml.get_dataset(dataset_id=61)
30+
# Old path still works:
31+
# dataset = openml.datasets.get_dataset(dataset_id=61)
2632

2733
# Print a summary
2834
print(

examples/Basics/simple_flows_and_runs_tutorial.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
# NOTE: We are using task 119 from the test server: https://test.openml.org/d/20
3030

3131
# %%
32-
task = openml.tasks.get_task(119)
32+
# New: top-level convenience alias
33+
task = openml.get_task(119)
34+
# Old path still works:
35+
# task = openml.tasks.get_task(119)
3336

3437
# Get the data
3538
dataset = task.get_dataset()
@@ -54,7 +57,7 @@
5457

5558
# %% [markdown]
5659
# ## Upload the machine learning experiments to OpenML
57-
# First, create a fow and fill it with metadata about the machine learning model.
60+
# First, create a flow and fill it with metadata about the machine learning model.
5861

5962
# %%
6063
knn_flow = openml.flows.OpenMLFlow(

examples/Basics/simple_tasks_tutorial.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
# [supervised classification on credit-g](https://www.openml.org/search?type=task&id=31&source_data.data_id=31):
1111

1212
# %%
13-
task = openml.tasks.get_task(31)
13+
# New: top-level convenience alias
14+
task = openml.get_task(31)
15+
# Old path still works:
16+
# task = openml.tasks.get_task(31)
1417

1518
# %% [markdown]
1619
# Get the dataset and its data from the task.

openml/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
from .__version__ import __version__
3838
from ._api import _backend
3939
from .datasets import OpenMLDataFeature, OpenMLDataset
40+
from .datasets.functions import get_dataset, list_datasets
4041
from .evaluations import OpenMLEvaluation
4142
from .flows import OpenMLFlow
43+
from .flows.functions import get_flow, list_flows
4244
from .runs import OpenMLRun
45+
from .runs.functions import get_run, list_runs
4346
from .setups import OpenMLParameter, OpenMLSetup
4447
from .study import OpenMLBenchmarkSuite, OpenMLStudy
4548
from .tasks import (
@@ -51,6 +54,7 @@
5154
OpenMLSupervisedTask,
5255
OpenMLTask,
5356
)
57+
from .tasks.functions import get_task, list_tasks
5458

5559
if TYPE_CHECKING:
5660
from ._config import OpenMLConfigManager
@@ -124,6 +128,14 @@ def populate_cache(
124128
"exceptions",
125129
"extensions",
126130
"flows",
131+
"get_dataset",
132+
"get_flow",
133+
"get_run",
134+
"get_task",
135+
"list_datasets",
136+
"list_flows",
137+
"list_runs",
138+
"list_tasks",
127139
"runs",
128140
"setups",
129141
"study",

tests/test_openml/test_openml.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,17 @@ def test_populate_cache(
4141
assert task_mock.call_count == 2
4242
for argument, fixture in zip(task_mock.call_args_list, [(1,), (2,)]):
4343
assert argument[0] == fixture
44+
45+
def test_top_level_getters_aliases(self):
46+
# Ensure top-level convenience aliases point to existing implementations.
47+
assert openml.list_datasets is openml.datasets.list_datasets
48+
assert openml.get_dataset is openml.datasets.get_dataset
49+
50+
assert openml.list_flows is openml.flows.list_flows
51+
assert openml.get_flow is openml.flows.get_flow
52+
53+
assert openml.list_runs is openml.runs.list_runs
54+
assert openml.get_run is openml.runs.get_run
55+
56+
assert openml.list_tasks is openml.tasks.list_tasks
57+
assert openml.get_task is openml.tasks.get_task

0 commit comments

Comments
 (0)