scikit-lego
scikit-lego copied to clipboard
[BUG] Future stability of meta-modelling
Scikit-lego is a great asset and the future of this library is important. The meta-modelling option employs the from sklearn.utils.metaestimators import if_delegate_has_method
method. However, this method is depreciated in the most recent scikit-learn release and will be removed in version 1.3, which will be an issue. The new call method is available_if
. Hopefully the integration of this new method will be simple and changes can be made. Thanks for all the amazing work so far.
Ah! That's a good ping 😄 thanks for reporting.
I suppose this falls into another discussion on the topic of "what do we want to keep supporting". It feels like we might need to start forcing our users to use a modern sklearn version at some point, and we've been able to keep our sklearn dependency to >=0.24.*
since the inception of this project.
If anybody wants to pick this up, feel free to ping, but let's discuss the implementation before making a PR.
I wouldn't mind upping the lowest supported version. available_if
has been around since sklearn==1.0
I think, which is about a year old already
If you still want to maintain the current sklearn requirement, here is a possible option:
from packaging.version import Version
import sklearn
import sklearn.utils.metaestimators
sk_version = 1 if Version(sklearn.__version__)>=Version('1.3.0') else 0
meta_dict = {0:"if_delegate_has_method", 1:"available_if"}
if_delegate_has_method = getattr(sklearn.utils.metaestimators, meta_dict[sk_version])
With this method you won't have to modify anywhere where if_delegate_has_method
is called either as a bonus. Note packaging
is a python builtin library, so no additional install requirements either.
Are the APIs 1-to-1 compatible though? I thought I remembered the available_if
method taking a reference to a function and the if_delegate_has_method
a string. If they are compatible, I'd suggest the following
try:
from sklearn.utils.metaestimators import available_if
except ImportError
import sklearn.utils.metaestimators.if_delegate_has_method as available_if