From 9ffcb4dca7f8a67e662f27d17a38e339fa5e3681 Mon Sep 17 00:00:00 2001 From: Jayant-kernel Date: Fri, 25 Sep 2026 20:04:41 +0530 Subject: [PATCH 1/3] [ENH] Include estimation procedure metadata Signed-off-by: Jayant-kernel --- openml/evaluations/__init__.py | 8 +++- openml/evaluations/functions.py | 38 +++++++++++++-- .../test_evaluation_functions.py | 48 +++++++++++++++++++ 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/openml/evaluations/__init__.py b/openml/evaluations/__init__.py index b56d0c2d5c..29344b03a1 100644 --- a/openml/evaluations/__init__.py +++ b/openml/evaluations/__init__.py @@ -1,10 +1,16 @@ # License: BSD 3-Clause from .evaluation import OpenMLEvaluation -from .functions import list_evaluation_measures, list_evaluations, list_evaluations_setups +from .functions import ( + list_estimation_procedures, + list_evaluation_measures, + list_evaluations, + list_evaluations_setups, +) __all__ = [ "OpenMLEvaluation", + "list_estimation_procedures", "list_evaluation_measures", "list_evaluations", "list_evaluations_setups", diff --git a/openml/evaluations/functions.py b/openml/evaluations/functions.py index 4f4c3baea6..42556e8353 100644 --- a/openml/evaluations/functions.py +++ b/openml/evaluations/functions.py @@ -156,18 +156,46 @@ def list_evaluation_measures() -> list[str]: return openml._backend.evaluation_measure.list() -def list_estimation_procedures() -> list[str]: - """Return list of evaluation procedures available. +@overload +def list_estimation_procedures( + output_format: Literal["dataframe"], +) -> pd.DataFrame: ... + + +@overload +def list_estimation_procedures( + output_format: Literal["dict"] = ..., +) -> dict[int, dict[str, object]]: ... + + +def list_estimation_procedures( + output_format: Literal["dict", "dataframe"] = "dict", +) -> dict[int, dict[str, object]] | pd.DataFrame: + """Return the estimation procedures available on OpenML. The function performs an API call to retrieve the entire list of - evaluation procedures' names that are available. + evaluation procedures. Each procedure includes its ID, task type, + name, and type. + + Parameters + ---------- + output_format : {"dict", "dataframe"}, default="dict" + The format of the returned procedures. The dictionary format maps + procedure IDs to their remaining metadata. The DataFrame format has + one row per procedure, including an ``id`` column. Returns ------- - list + dict or pandas.DataFrame + The available estimation procedures in the requested format. """ result = openml._backend.estimation_procedure.list() - return [i.name for i in result] + records = [procedure._to_dict() for procedure in result] + + if output_format == "dataframe": + return pd.DataFrame.from_records(records) + + return {record.pop("id"): record for record in records} def list_evaluations_setups( diff --git a/tests/test_evaluations/test_evaluation_functions.py b/tests/test_evaluations/test_evaluation_functions.py index de65ca0b8b..cddebf2112 100644 --- a/tests/test_evaluations/test_evaluation_functions.py +++ b/tests/test_evaluations/test_evaluation_functions.py @@ -1,10 +1,14 @@ # License: BSD 3-Clause from __future__ import annotations +from unittest.mock import patch + import pytest import openml import openml.evaluations +from openml.estimation_procedures import OpenMLEstimationProcedure +from openml.tasks import TaskType def _check_list_evaluation_setups(long_version, **kwargs): @@ -226,6 +230,50 @@ def test_evaluation_list_sort(): assert test_output[:size] == sorted_output +def test_list_estimation_procedures_dict(): + procedures = [ + OpenMLEstimationProcedure( + id=5, + task_type_id=TaskType.SUPERVISED_CLASSIFICATION, + name="10-fold Crossvalidation", + type="crossvalidation", + ) + ] + with patch.object(openml._backend.estimation_procedure, "list", return_value=procedures): + result = openml.evaluations.list_estimation_procedures() + + assert result == { + 5: { + "task_type_id": TaskType.SUPERVISED_CLASSIFICATION, + "name": "10-fold Crossvalidation", + "type": "crossvalidation", + } + } + + +def test_list_estimation_procedures_dataframe(): + procedures = [ + OpenMLEstimationProcedure( + id=5, + task_type_id=TaskType.SUPERVISED_CLASSIFICATION, + name="10-fold Crossvalidation", + type="crossvalidation", + ) + ] + with patch.object(openml._backend.estimation_procedure, "list", return_value=procedures): + result = openml.evaluations.list_estimation_procedures(output_format="dataframe") + + assert list(result.columns) == ["id", "task_type_id", "name", "type"] + assert result.to_dict("records") == [ + { + "id": 5, + "task_type_id": TaskType.SUPERVISED_CLASSIFICATION, + "name": "10-fold Crossvalidation", + "type": "crossvalidation", + } + ] + + @pytest.mark.test_server def test_list_evaluation_measures(): measures = openml.evaluations.list_evaluation_measures() From 4427d82b508ef71722ad0678b61d4e9562e1914f Mon Sep 17 00:00:00 2001 From: Jayant-kernel Date: Thu, 1 Oct 2026 20:08:42 +0530 Subject: [PATCH 2/3] [ENH] Preserve estimation procedure list compatibility --- openml/evaluations/functions.py | 49 +++++++++++++------ .../test_evaluation_functions.py | 28 +++++++---- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/openml/evaluations/functions.py b/openml/evaluations/functions.py index 42556e8353..2cdaf4911b 100644 --- a/openml/evaluations/functions.py +++ b/openml/evaluations/functions.py @@ -2,6 +2,7 @@ # ruff: noqa: PLR0913,PLR0917 from __future__ import annotations +import warnings from functools import partial from itertools import chain from typing import TYPE_CHECKING, Literal @@ -15,6 +16,7 @@ import openml.utils if TYPE_CHECKING: + from openml.estimation_procedures import OpenMLEstimationProcedure from openml.evaluations import OpenMLEvaluation @@ -164,38 +166,57 @@ def list_estimation_procedures( @overload def list_estimation_procedures( - output_format: Literal["dict"] = ..., -) -> dict[int, dict[str, object]]: ... + output_format: Literal["object"], +) -> dict[int, OpenMLEstimationProcedure]: ... + + +@overload +def list_estimation_procedures( + output_format: None = None, +) -> list[str]: ... def list_estimation_procedures( - output_format: Literal["dict", "dataframe"] = "dict", -) -> dict[int, dict[str, object]] | pd.DataFrame: + output_format: Literal["object", "dataframe"] | None = None, +) -> list[str] | dict[int, OpenMLEstimationProcedure] | pd.DataFrame: """Return the estimation procedures available on OpenML. The function performs an API call to retrieve the entire list of - evaluation procedures. Each procedure includes its ID, task type, - name, and type. + evaluation procedures. Parameters ---------- - output_format : {"dict", "dataframe"}, default="dict" - The format of the returned procedures. The dictionary format maps - procedure IDs to their remaining metadata. The DataFrame format has - one row per procedure, including an ``id`` column. + output_format : {"object", "dataframe"}, optional + The format of the returned procedures. ``"object"`` returns a + dictionary mapping procedure IDs to ``OpenMLEstimationProcedure`` + instances. ``"dataframe"`` returns one row per procedure. + If omitted, a list of procedure names is returned for backwards + compatibility and a warning is emitted. Returns ------- - dict or pandas.DataFrame + list[str], dict[int, OpenMLEstimationProcedure], or pandas.DataFrame The available estimation procedures in the requested format. """ result = openml._backend.estimation_procedure.list() - records = [procedure._to_dict() for procedure in result] + + if output_format is None: + warnings.warn( + "The default output will change from a list of names to a dictionary of " + "OpenMLEstimationProcedure objects in a future release. Set " + "output_format='object' to use the new format.", + FutureWarning, + stacklevel=2, + ) + return [procedure.name for procedure in result] if output_format == "dataframe": - return pd.DataFrame.from_records(records) + return pd.DataFrame.from_records(procedure._to_dict() for procedure in result) + + if output_format == "object": + return {procedure.id: procedure for procedure in result} - return {record.pop("id"): record for record in records} + raise ValueError("Invalid output format. Only 'object' and 'dataframe' are applicable.") def list_evaluations_setups( diff --git a/tests/test_evaluations/test_evaluation_functions.py b/tests/test_evaluations/test_evaluation_functions.py index cddebf2112..349b0cd4b0 100644 --- a/tests/test_evaluations/test_evaluation_functions.py +++ b/tests/test_evaluations/test_evaluation_functions.py @@ -230,7 +230,7 @@ def test_evaluation_list_sort(): assert test_output[:size] == sorted_output -def test_list_estimation_procedures_dict(): +def test_list_estimation_procedures_default_warns_about_future_change(): procedures = [ OpenMLEstimationProcedure( id=5, @@ -239,16 +239,26 @@ def test_list_estimation_procedures_dict(): type="crossvalidation", ) ] - with patch.object(openml._backend.estimation_procedure, "list", return_value=procedures): + with ( + patch.object(openml._backend.estimation_procedure, "list", return_value=procedures), + pytest.warns(FutureWarning, match="output will change"), + ): result = openml.evaluations.list_estimation_procedures() - assert result == { - 5: { - "task_type_id": TaskType.SUPERVISED_CLASSIFICATION, - "name": "10-fold Crossvalidation", - "type": "crossvalidation", - } - } + assert result == ["10-fold Crossvalidation"] + + +def test_list_estimation_procedures_object(): + procedure = OpenMLEstimationProcedure( + id=5, + task_type_id=TaskType.SUPERVISED_CLASSIFICATION, + name="10-fold Crossvalidation", + type="crossvalidation", + ) + with patch.object(openml._backend.estimation_procedure, "list", return_value=[procedure]): + result = openml.evaluations.list_estimation_procedures(output_format="object") + + assert result == {5: procedure} def test_list_estimation_procedures_dataframe(): From 2b33419fbfaae96a75f50a58564acbb52d272d13 Mon Sep 17 00:00:00 2001 From: Jayant-kernel Date: Fri, 27 Nov 2026 17:01:46 +0530 Subject: [PATCH 3/3] [ENH] Opt in to full estimation procedure objects --- openml/evaluations/functions.py | 62 ++++++------------- .../test_evaluation_functions.py | 33 ++-------- 2 files changed, 23 insertions(+), 72 deletions(-) diff --git a/openml/evaluations/functions.py b/openml/evaluations/functions.py index 2cdaf4911b..959cabd625 100644 --- a/openml/evaluations/functions.py +++ b/openml/evaluations/functions.py @@ -158,27 +158,10 @@ def list_evaluation_measures() -> list[str]: return openml._backend.evaluation_measure.list() -@overload -def list_estimation_procedures( - output_format: Literal["dataframe"], -) -> pd.DataFrame: ... - - -@overload -def list_estimation_procedures( - output_format: Literal["object"], -) -> dict[int, OpenMLEstimationProcedure]: ... - - -@overload def list_estimation_procedures( - output_format: None = None, -) -> list[str]: ... - - -def list_estimation_procedures( - output_format: Literal["object", "dataframe"] | None = None, -) -> list[str] | dict[int, OpenMLEstimationProcedure] | pd.DataFrame: + *, + get_procedures: bool = False, +) -> list[str] | list[OpenMLEstimationProcedure]: """Return the estimation procedures available on OpenML. The function performs an API call to retrieve the entire list of @@ -186,37 +169,28 @@ def list_estimation_procedures( Parameters ---------- - output_format : {"object", "dataframe"}, optional - The format of the returned procedures. ``"object"`` returns a - dictionary mapping procedure IDs to ``OpenMLEstimationProcedure`` - instances. ``"dataframe"`` returns one row per procedure. - If omitted, a list of procedure names is returned for backwards - compatibility and a warning is emitted. + get_procedures : bool, default=False + Return full procedure objects when True. By default, return the + procedure names and emit a warning about the future change. Returns ------- - list[str], dict[int, OpenMLEstimationProcedure], or pandas.DataFrame - The available estimation procedures in the requested format. + list[str] or list[OpenMLEstimationProcedure] + The available estimation procedure names or full procedure objects. """ result = openml._backend.estimation_procedure.list() - if output_format is None: - warnings.warn( - "The default output will change from a list of names to a dictionary of " - "OpenMLEstimationProcedure objects in a future release. Set " - "output_format='object' to use the new format.", - FutureWarning, - stacklevel=2, - ) - return [procedure.name for procedure in result] + if get_procedures: + return result - if output_format == "dataframe": - return pd.DataFrame.from_records(procedure._to_dict() for procedure in result) - - if output_format == "object": - return {procedure.id: procedure for procedure in result} - - raise ValueError("Invalid output format. Only 'object' and 'dataframe' are applicable.") + warnings.warn( + "The default output will change from a list of names to a list of " + "OpenMLEstimationProcedure objects in a future release. Set " + "get_procedures=True to use the new format.", + FutureWarning, + stacklevel=2, + ) + return [procedure.name for procedure in result] def list_evaluations_setups( diff --git a/tests/test_evaluations/test_evaluation_functions.py b/tests/test_evaluations/test_evaluation_functions.py index 349b0cd4b0..28547a557a 100644 --- a/tests/test_evaluations/test_evaluation_functions.py +++ b/tests/test_evaluations/test_evaluation_functions.py @@ -230,7 +230,7 @@ def test_evaluation_list_sort(): assert test_output[:size] == sorted_output -def test_list_estimation_procedures_default_warns_about_future_change(): +def test_list_estimation_procedures_default_warns_about_future_change() -> None: procedures = [ OpenMLEstimationProcedure( id=5, @@ -241,14 +241,14 @@ def test_list_estimation_procedures_default_warns_about_future_change(): ] with ( patch.object(openml._backend.estimation_procedure, "list", return_value=procedures), - pytest.warns(FutureWarning, match="output will change"), + pytest.warns(FutureWarning, match="get_procedures=True"), ): result = openml.evaluations.list_estimation_procedures() assert result == ["10-fold Crossvalidation"] -def test_list_estimation_procedures_object(): +def test_list_estimation_procedures_returns_objects_when_requested() -> None: procedure = OpenMLEstimationProcedure( id=5, task_type_id=TaskType.SUPERVISED_CLASSIFICATION, @@ -256,32 +256,9 @@ def test_list_estimation_procedures_object(): type="crossvalidation", ) with patch.object(openml._backend.estimation_procedure, "list", return_value=[procedure]): - result = openml.evaluations.list_estimation_procedures(output_format="object") + result = openml.evaluations.list_estimation_procedures(get_procedures=True) - assert result == {5: procedure} - - -def test_list_estimation_procedures_dataframe(): - procedures = [ - OpenMLEstimationProcedure( - id=5, - task_type_id=TaskType.SUPERVISED_CLASSIFICATION, - name="10-fold Crossvalidation", - type="crossvalidation", - ) - ] - with patch.object(openml._backend.estimation_procedure, "list", return_value=procedures): - result = openml.evaluations.list_estimation_procedures(output_format="dataframe") - - assert list(result.columns) == ["id", "task_type_id", "name", "type"] - assert result.to_dict("records") == [ - { - "id": 5, - "task_type_id": TaskType.SUPERVISED_CLASSIFICATION, - "name": "10-fold Crossvalidation", - "type": "crossvalidation", - } - ] + assert result == [procedure] @pytest.mark.test_server