Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion openml/evaluations/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 28 additions & 5 deletions openml/evaluations/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +16,7 @@
import openml.utils

if TYPE_CHECKING:
from openml.estimation_procedures import OpenMLEstimationProcedure
from openml.evaluations import OpenMLEvaluation


Expand Down Expand Up @@ -156,18 +158,39 @@ def list_evaluation_measures() -> list[str]:
return openml._backend.evaluation_measure.list()


def list_estimation_procedures() -> list[str]:
"""Return list of evaluation procedures available.
def list_estimation_procedures(
*,
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
evaluation procedures' names that are available.
evaluation procedures.

Parameters
----------
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
list[str] or list[OpenMLEstimationProcedure]
The available estimation procedure names or full procedure objects.
"""
result = openml._backend.estimation_procedure.list()
return [i.name for i in result]

if get_procedures:
return result

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(
Expand Down
35 changes: 35 additions & 0 deletions tests/test_evaluations/test_evaluation_functions.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -226,6 +230,37 @@ def test_evaluation_list_sort():
assert test_output[:size] == sorted_output


def test_list_estimation_procedures_default_warns_about_future_change() -> None:
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),
pytest.warns(FutureWarning, match="get_procedures=True"),
):
result = openml.evaluations.list_estimation_procedures()

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


def test_list_estimation_procedures_returns_objects_when_requested() -> None:
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(get_procedures=True)

assert result == [procedure]


@pytest.mark.test_server
def test_list_evaluation_measures():
measures = openml.evaluations.list_evaluation_measures()
Expand Down