Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor sub modules #78

Merged
merged 22 commits into from
Dec 7, 2022
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Additional lookup refactor
  • Loading branch information
RNKuhns committed Nov 22, 2022
commit 287de55c7e850e9b6af916d30215b75ce9848159
78 changes: 2 additions & 76 deletions skbase/lookup/_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
Union,
)

from skbase import BaseObject
from skbase.base import BaseObject
from skbase.validate import _check_list_of_str_or_error

# Conditionally import TypedDict based on Python version
if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -842,81 +843,6 @@ def _is_in_object_types(estimator, object_types):
return all_estimators


def _check_list_of_str_or_error(arg_to_check, arg_name):
"""Check that certain arguments are str or list of str.

Parameters
----------
arg_to_check: any
Argument we are testing the type of.
arg_name: str,
name of the argument we are testing, will be added to the error if
``arg_to_check`` is not a str or a list of str.

Returns
-------
arg_to_check: list of str,
if arg_to_check was originally a str it converts it into a list of str
so that it can be iterated over.

Raises
------
TypeError if arg_to_check is not a str or list of str.
"""
# check that return_tags has the right type:
if isinstance(arg_to_check, str):
arg_to_check = [arg_to_check]
elif not isinstance(arg_to_check, list) or not all(
isinstance(value, str) for value in arg_to_check
):
raise TypeError(
f"Input error. Argument {arg_name} must be either\
a str or list of str"
)
return arg_to_check


def _check_iterable_of_class_or_error(arg_to_check, arg_name, coerce_to_list=False):
"""Check that certain arguments are class or list of class.

Parameters
----------
arg_to_check: any
Argument we are testing the type of.
arg_name: str
name of the argument we are testing, will be added to the error if
``arg_to_check`` is not a str or a list of str.
coerce_to_list : bool, default=False
Whether `arg_to_check` should be coerced to a list prior to return.

Returns
-------
arg_to_check: list of class,
If `arg_to_check` was originally a class it converts it into a list
containing the class so it can be iterated over. Otherwise,
`arg_to_check` is returned.

Raises
------
TypeError:
If `arg_to_check` is not a class or iterable of class.
"""
# check that return_tags has the right type:
if inspect.isclass(arg_to_check):
arg_to_check = [arg_to_check]
elif not (
isinstance(arg_to_check, Iterable)
and all(inspect.isclass(value) for value in arg_to_check)
):
raise TypeError(
f"Input error. Argument {arg_name} must be either\
a class or an iterable of classes"
)
elif coerce_to_list:
arg_to_check = list(arg_to_check)
return arg_to_check


def _get_return_tags(obj, return_tags):
"""Fetch a list of all tags for every_entry of all_estimators.

Expand Down