Skip to content

Commit

Permalink
[ENH] allow_empty option in _MetaObjectMixin._check_objects (#386)
Browse files Browse the repository at this point in the history
This PR adds an `allow_empty` option in
`_MetaObjectMixin._check_objects`, which allows for the edge case of
empty list - this may be useful in some meta-estimators.
  • Loading branch information
fkiraly authored Dec 6, 2024
1 parent 5adfc16 commit 8bfa0f4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions skbase/base/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def _check_objects(
cls_type=None,
allow_dict=False,
allow_mix=True,
allow_empty=False,
clone=True,
):
"""Check that objects is a list of objects or sequence of named objects.
Expand All @@ -373,10 +374,14 @@ def _check_objects(
Name of checked attribute in error messages.
cls_type : class or tuple of classes, default=BaseEstimator.
class(es) that all objects are checked to be an instance of.
allow_dict : bool, default=False
Whether ``objs`` can be a dictionary mapping str names to objects.
allow_mix : bool, default=True
Whether mix of objects and (str, objects) is allowed in `objs.`
Whether mix of objects and (str, objects) is allowed in ``objs``.
allow_empty : bool, default=False
Whether ``objs`` can be empty.
clone : bool, default=True
Whether objects or named objects in `objs` are returned as clones
Whether objects or named objects in ``objs`` are returned as clones
(True) or references (False).
Returns
Expand Down Expand Up @@ -421,7 +426,7 @@ def _check_objects(

if (
objs is None
or len(objs) == 0
or (not allow_empty and len(objs) == 0)
or not (isinstance(objs, list) or (allow_dict and isinstance(objs, dict)))
):
raise TypeError(msg)
Expand Down

0 comments on commit 8bfa0f4

Please sign in to comment.