Skip to content

Commit 2b33419

Browse files
committed
[ENH] Opt in to full estimation procedure objects
1 parent bafe059 commit 2b33419

2 files changed

Lines changed: 23 additions & 72 deletions

File tree

‎openml/evaluations/functions.py‎

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -158,65 +158,39 @@ def list_evaluation_measures() -> list[str]:
158158
return openml._backend.evaluation_measure.list()
159159

160160

161-
@overload
162-
def list_estimation_procedures(
163-
output_format: Literal["dataframe"],
164-
) -> pd.DataFrame: ...
165-
166-
167-
@overload
168-
def list_estimation_procedures(
169-
output_format: Literal["object"],
170-
) -> dict[int, OpenMLEstimationProcedure]: ...
171-
172-
173-
@overload
174161
def list_estimation_procedures(
175-
output_format: None = None,
176-
) -> list[str]: ...
177-
178-
179-
def list_estimation_procedures(
180-
output_format: Literal["object", "dataframe"] | None = None,
181-
) -> list[str] | dict[int, OpenMLEstimationProcedure] | pd.DataFrame:
162+
*,
163+
get_procedures: bool = False,
164+
) -> list[str] | list[OpenMLEstimationProcedure]:
182165
"""Return the estimation procedures available on OpenML.
183166
184167
The function performs an API call to retrieve the entire list of
185168
evaluation procedures.
186169
187170
Parameters
188171
----------
189-
output_format : {"object", "dataframe"}, optional
190-
The format of the returned procedures. ``"object"`` returns a
191-
dictionary mapping procedure IDs to ``OpenMLEstimationProcedure``
192-
instances. ``"dataframe"`` returns one row per procedure.
193-
If omitted, a list of procedure names is returned for backwards
194-
compatibility and a warning is emitted.
172+
get_procedures : bool, default=False
173+
Return full procedure objects when True. By default, return the
174+
procedure names and emit a warning about the future change.
195175
196176
Returns
197177
-------
198-
list[str], dict[int, OpenMLEstimationProcedure], or pandas.DataFrame
199-
The available estimation procedures in the requested format.
178+
list[str] or list[OpenMLEstimationProcedure]
179+
The available estimation procedure names or full procedure objects.
200180
"""
201181
result = openml._backend.estimation_procedure.list()
202182

203-
if output_format is None:
204-
warnings.warn(
205-
"The default output will change from a list of names to a dictionary of "
206-
"OpenMLEstimationProcedure objects in a future release. Set "
207-
"output_format='object' to use the new format.",
208-
FutureWarning,
209-
stacklevel=2,
210-
)
211-
return [procedure.name for procedure in result]
183+
if get_procedures:
184+
return result
212185

213-
if output_format == "dataframe":
214-
return pd.DataFrame.from_records(procedure._to_dict() for procedure in result)
215-
216-
if output_format == "object":
217-
return {procedure.id: procedure for procedure in result}
218-
219-
raise ValueError("Invalid output format. Only 'object' and 'dataframe' are applicable.")
186+
warnings.warn(
187+
"The default output will change from a list of names to a list of "
188+
"OpenMLEstimationProcedure objects in a future release. Set "
189+
"get_procedures=True to use the new format.",
190+
FutureWarning,
191+
stacklevel=2,
192+
)
193+
return [procedure.name for procedure in result]
220194

221195

222196
def list_evaluations_setups(

‎tests/test_evaluations/test_evaluation_functions.py‎

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def test_evaluation_list_sort():
230230
assert test_output[:size] == sorted_output
231231

232232

233-
def test_list_estimation_procedures_default_warns_about_future_change():
233+
def test_list_estimation_procedures_default_warns_about_future_change() -> None:
234234
procedures = [
235235
OpenMLEstimationProcedure(
236236
id=5,
@@ -241,47 +241,24 @@ def test_list_estimation_procedures_default_warns_about_future_change():
241241
]
242242
with (
243243
patch.object(openml._backend.estimation_procedure, "list", return_value=procedures),
244-
pytest.warns(FutureWarning, match="output will change"),
244+
pytest.warns(FutureWarning, match="get_procedures=True"),
245245
):
246246
result = openml.evaluations.list_estimation_procedures()
247247

248248
assert result == ["10-fold Crossvalidation"]
249249

250250

251-
def test_list_estimation_procedures_object():
251+
def test_list_estimation_procedures_returns_objects_when_requested() -> None:
252252
procedure = OpenMLEstimationProcedure(
253253
id=5,
254254
task_type_id=TaskType.SUPERVISED_CLASSIFICATION,
255255
name="10-fold Crossvalidation",
256256
type="crossvalidation",
257257
)
258258
with patch.object(openml._backend.estimation_procedure, "list", return_value=[procedure]):
259-
result = openml.evaluations.list_estimation_procedures(output_format="object")
259+
result = openml.evaluations.list_estimation_procedures(get_procedures=True)
260260

261-
assert result == {5: procedure}
262-
263-
264-
def test_list_estimation_procedures_dataframe():
265-
procedures = [
266-
OpenMLEstimationProcedure(
267-
id=5,
268-
task_type_id=TaskType.SUPERVISED_CLASSIFICATION,
269-
name="10-fold Crossvalidation",
270-
type="crossvalidation",
271-
)
272-
]
273-
with patch.object(openml._backend.estimation_procedure, "list", return_value=procedures):
274-
result = openml.evaluations.list_estimation_procedures(output_format="dataframe")
275-
276-
assert list(result.columns) == ["id", "task_type_id", "name", "type"]
277-
assert result.to_dict("records") == [
278-
{
279-
"id": 5,
280-
"task_type_id": TaskType.SUPERVISED_CLASSIFICATION,
281-
"name": "10-fold Crossvalidation",
282-
"type": "crossvalidation",
283-
}
284-
]
261+
assert result == [procedure]
285262

286263

287264
@pytest.mark.test_server

0 commit comments

Comments
 (0)