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

[ENH] add _get_clone_plugins to allow packages to customize clone plugins #383

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
32 changes: 31 additions & 1 deletion skbase/base/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,41 @@ def clone(self):
------
RuntimeError if the clone is non-conforming, due to faulty ``__init__``.
"""
self_clone = _clone(self, base_cls=BaseObject)
# get plugins for cloning, if present (empty by default)
clone_plugins = self._get_clone_plugins()

# clone the object
self_clone = _clone(self, base_cls=BaseObject, clone_plugins=clone_plugins)

# check the clone, if check_clone is set (False by default)
if self.get_config()["check_clone"]:
_check_clone(original=self, clone=self_clone)

# return the clone
return self_clone

@classmethod
def _get_clone_plugins(cls):
"""Get clone plugins for BaseObject.
Can be overridden in subclasses to add custom clone plugins.
If implemented, must return a list of clone plugins for descendants.
Plugins are loaded ahead of the default plugins, and are used in the order
they are returned.
This allows extenders to override the default behaviours, if desired.
Returns
-------
list of str
List of clone plugins for descendants.
Each plugin must inherit from ``BaseCloner``
in ``skbase.base._clone_plugins``, and implement
the methods ``_check`` and ``_clone``.
"""
return None

@classmethod
def _get_init_signature(cls):
"""Get class init signature.
Expand Down
Loading