epsilon-machine / missingpy

Missing Data Imputation for Python
GNU General Public License v3.0
240 stars 64 forks source link

_check_weights() no longer exists in SciKit-learn #41

Open franzhuettinger opened 5 months ago

franzhuettinger commented 5 months ago

_check_weights() was removed from sklearn after version 1.2.X. Therefore, missingpy is no longer compatible with the latest version of SciKit-learn.

As a quick fix I copied the original code from the sklearn/neighbors/_base.py file (version 0.22.X) to my local copy of missingpy/knnimpute.py:

def _check_weights(weights):
    """Check to make sure weights are valid"""
    if weights in (None, 'uniform', 'distance'):
        return weights
    elif callable(weights):
        return weights
    else:
        raise ValueError("weights not recognized: should be 'uniform', "
                         "'distance', or a callable function")

... and removed the import:

# from sklearn.neighbors.base import _check_weight