Replace force_all_finite with ensure_all_finite to Address FutureWarning
The use of the force_all_finite in the check_array method is causing a FutureWarning due to a recent deprecation in scikit-learn. According to the warning, force_all_finite has been renamed to ensure_all_finite in scikit-learn version 1.6 and will be removed in version 1.8.
https://github.com/scikit-learn/scikit-learn/issues/29262
If I change it now, it will break compatability with all earlier releases of sklearn. For this reason I think it will be better to accept some deprecation warnings and wait a while before making the change.
If I change it now, it will break compatability with all earlier releases of sklearn. For this reason I think it will be better to accept some deprecation warnings and wait a while before making the change.
Though not that elegant, I think an alternative workaround is something like this:
import sklearn
from sklearn.utils import check_array as _check_array
sklearn_ver = list(map(int,sklearn.__version__))
_new_check_array_api = sklearn_ver[0]>=1 and sklearn_ver[1]>=6
def check_array(*args,ensure_all_finite=None,**kwargs):
if _new_check_array_api:
return _check_array(*args,force_all_finite=ensure_all_finite,**kwargs)
else:
return _check_array(*args,ensure_all_finite=ensure_all_finite,**kwargs)
@lmcinnes the best version to deal with this is the way @fncokg suggests.
it prevents you from forgetting and will make a bigger range of your package’s versions compatible, reducing pain for users.
Though not that elegant
@fncokg this is as elegant as it gets!
If I change it now, it will break compatability with all earlier releases of sklearn. For this reason I think it will be better to accept some deprecation warnings and wait a while before making the change.
Though not that elegant, I think an alternative workaround is something like this:
import sklearn from sklearn.utils import check_array as _check_array
sklearn_ver = list(map(int,sklearn.version)) _new_check_array_api = sklearn_ver[0]>=1 and sklearn_ver[1]>=6
def check_array(*args,ensure_all_finite=None,**kwargs): if _new_check_array_api: return _check_array(*args,force_all_finite=ensure_all_finite,**kwargs) else: return _check_array(*args,ensure_all_finite=ensure_all_finite,**kwargs)
I stumbled on this issue trying to fix this in another package. Like the solution.
I realized that there may be alphanumeric characters in a version i.e. 1.4.1.post1, 1.22.dev0, 1.7.0rc1. One might need to use packaging to compare the versions so the map(int, ...) doesn't fail for a post release.
There could also be dev or rc releases.
you’re right, I missed the version comparison. Yes, packaging is the way to go!
@lmcinnes as a heads up: scikit-learn 1.8 is probably going to be released tomorrow (or shortly after).
To have one version of umap that works with several versions of scikit-learn will need a shim that can take care of the translation. I think that is probably worth the effort. There is a suggestion in this thread, there is also https://github.com/sklearn-compat/sklearn-compat#validate_data-function which might be useful in general for helping with compatibility between versions - maybe adopting that is a bigger decision for a quiet moment?