umap icon indicating copy to clipboard operation
umap copied to clipboard

Replace force_all_finite with ensure_all_finite to Address FutureWarning

Open aminsabzmakan opened this issue 1 year ago • 7 comments

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

aminsabzmakan avatar Jan 06 '25 20:01 aminsabzmakan

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.

lmcinnes avatar Jan 07 '25 15:01 lmcinnes

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)

fncokg avatar May 13 '25 14:05 fncokg

@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!

flying-sheep avatar Jul 21 '25 11:07 flying-sheep

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.

jmahlik avatar Jul 22 '25 18:07 jmahlik

you’re right, I missed the version comparison. Yes, packaging is the way to go!

flying-sheep avatar Jul 22 '25 18:07 flying-sheep

@lmcinnes as a heads up: scikit-learn 1.8 is probably going to be released tomorrow (or shortly after).

betatim avatar Dec 08 '25 17:12 betatim

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?

betatim avatar Dec 09 '25 07:12 betatim