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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Hyperactive registry."""

from hyperactive._registry._lookup import all_objects
from hyperactive.registry._lookup import all_objects

__all__ = ["all_objects"]
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def all_objects(
Not included are: the base classes themselves, classes defined in test
modules.

To filter by object type, use the ``object_types`` parameter:

* ``"optimizer"``: optimizers, e.g., the Hill Climbing optimizer,
or the Particle Swarm optimizer
* ``"experiment"``: experiments, e.g., the Ackley function, or an ``sklearn``
cross-validation experiment
* if ``None``, no filter is applied and all objects are returned.

To filter by tag, use the ``filter_tags`` parameter.

Parameters
----------
object_types: str, list of str, optional (default=None)
Expand Down Expand Up @@ -137,7 +147,7 @@ def all_objects(

Examples
--------
>>> from hyperactive._registry import all_objects
>>> from hyperactive.registry import all_objects
>>> # return a complete list of objects as pd.Dataframe
>>> all_objects(as_dataframe=True) # doctest: +SKIP

Expand Down
1 change: 1 addition & 0 deletions src/hyperactive/registry/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Registry tests."""
52 changes: 52 additions & 0 deletions src/hyperactive/registry/tests/test_lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# copyright: hyperactive developers, BSD-3-Clause License (see LICENSE file)
"""Testing of registry lookup functionality."""

# based on the sktime module of same name

__author__ = ["fkiraly"]

import pytest

from hyperactive.registry import all_objects

object_types = ["optimizer", "experiment"]


def _to_list(obj):
"""Put obj in list if it is not a list."""
if not isinstance(obj, list):
return [obj]
else:
return obj.copy()


@pytest.mark.parametrize("return_names", [True, False])
@pytest.mark.parametrize("object_type", object_types)
def test_all_objects_by_scitype(object_type, return_names):
"""Check that all_objects return argument has correct type."""
objects = all_objects(
object_types=object_type,
return_names=return_names,
)

assert isinstance(objects, list)
# there should be at least one object returned
assert len(objects) > 0

# checks return type specification (see docstring)
for obj in objects:
if return_names:
assert isinstance(obj, tuple) and len(obj) == 2
name = obj[0]
obj_cls = obj[1]
assert isinstance(name, str)
assert hasattr(obj_cls, "__name__")
assert name == obj_cls.__name__
else:
obj_cls = obj

assert hasattr(obj_cls, "get_tags")
type_from_obj = obj_cls.get_class_tag("object_type")
type_from_obj = _to_list(type_from_obj)

assert object_type in type_from_obj
2 changes: 1 addition & 1 deletion src/hyperactive/tests/test_all_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from skbase.testing import QuickTester as _QuickTester
from skbase.testing import TestAllObjects as _TestAllObjects

from hyperactive._registry import all_objects
from hyperactive.registry import all_objects
from hyperactive.tests._config import EXCLUDE_ESTIMATORS, EXCLUDED_TESTS
from hyperactive.tests._doctest import run_doctest

Expand Down